us.ihmc.scs2.definition.yoGraphic.YoGraphicPointcloud2DDefinition Maven / Gradle / Ivy
package us.ihmc.scs2.definition.yoGraphic;
import java.util.List;
import java.util.Objects;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import us.ihmc.scs2.definition.yoComposite.YoTuple2DDefinition;
/**
* A {@code YoGraphicPointcloud2DDefinition} is a template for creating multiple 2D points and which
* components can be backed by {@code YoVariable}s.
*
*
* A 2D yoGraphic is rendered in the overhead plotter panel and it can be back by
* {@code YoVariable}s allowing it to move and change at runtime.
*
*
* The {@code YoGraphicPointcloud2DDefinition} is to be passed before initialization of a session
* (either before starting a simulation or when creating a yoVariable server), such that the SCS GUI
* can use the definitions and create the actual graphics.
*
*
* See {@link YoGraphicDefinitionFactory} for factory methods simplifying the creation of yoGraphic
* definitions.
*
*
* @author Sylvain Bertrand
*/
@XmlRootElement(name = "YoGraphicPointcloud3D")
public class YoGraphicPointcloud2DDefinition extends YoGraphic2DDefinition
{
/** The positions for the points. */
private List points;
/**
* The number of points to use in the {@link #points} list. When {@code null}, all the points will
* be rendered.
*/
private String numberOfPoints;
/** The size of the graphics, when rendered as circles, it corresponds to the diameter. */
private String size;
/**
* The graphic name used to retrieve the type of graphic to visualize the point as. Here are some
* examples:
*
* - "plus":
*
* - "cross":
*
* - "circle":
*
* - "circle_plus":
*
* - "circle_cross":
*
* - "diamond":
*
* - "diamond_plus":
*
* - "square":
*
* - "square_cross":
*
*
*/
private String graphicName;
/**
* Creates a new yoGraphic definition for rendering a series of points.
*
* Its components need to be initialized. See {@link YoGraphicDefinitionFactory} for factories to
* facilitate creation.
*
*/
public YoGraphicPointcloud2DDefinition()
{
registerListField("points", this::getPoints, this::setPoints, "p", Object::toString, YoTuple2DDefinition::parse);
registerStringField("numberOfPoints", this::getNumberOfPoints, this::setNumberOfPoints);
registerStringField("size", this::getSize, this::setSize);
registerStringField("graphicName", this::getGraphicName, this::setGraphicName);
}
/**
* Sets the positions for the points.
*
* @param position the position for the point.
*/
@XmlElement
public void setPoints(List points)
{
this.points = points;
}
/**
* Sets the number of points to use in the points list. When {@code null}, all the points will be
* rendered.
*
* This field can be backed with a {@code YoVariable} by giving the variable name/fullname.
*
*
* @param numberOfPoints the number of points to render.
*/
@XmlElement
public void setNumberOfPoints(String numberOfPoints)
{
this.numberOfPoints = numberOfPoints;
}
/**
* Sets the size of the graphic, when rendered as circles, it corresponds to the diameter.
*
* Using this method sets it to a constant value.
*
*
* @param size the size of the graphic.
*/
public void setSize(double size)
{
setSize(Double.toString(size));
}
/**
* Sets the size of the graphic, when rendered as circles, it corresponds to the diameter.
*
* Using this method allows to back the size with a {@code YoVariable} by giving the variable
* name/fullname.
*
*
* @param size the size of the graphic.
*/
@XmlElement
public void setSize(String size)
{
this.size = size;
}
/**
* Sets the type of the graphic:
*
* - "plus":
*
* - "cross":
*
* - "circle":
*
* - "circle_plus":
*
* - "circle_cross":
*
* - "diamond":
*
* - "diamond_plus":
*
* - "square":
*
* - "square_cross":
*
*
*
* @param graphicName the name of the graphic to use.
*/
@XmlElement
public void setGraphicName(String graphicName)
{
this.graphicName = graphicName;
}
public List getPoints()
{
return points;
}
public String getNumberOfPoints()
{
return numberOfPoints;
}
public String getSize()
{
return size;
}
public String getGraphicName()
{
return graphicName;
}
@Override
public boolean equals(Object object)
{
if (object == this)
{
return true;
}
else if (!super.equals(object))
{
return false;
}
else if (object instanceof YoGraphicPointcloud2DDefinition other)
{
if (!Objects.equals(points, other.points))
return false;
if (!Objects.equals(numberOfPoints, other.numberOfPoints))
return false;
if (!Objects.equals(size, other.size))
return false;
if (!Objects.equals(graphicName, other.graphicName))
return false;
return true;
}
else
{
return false;
}
}
@Override
public String toString(int indent)
{
String out = "%s [name=%s, visible=%b, fillColor=%s, strokeColor=%s, strokeWidth=%s, points=%s, numberOfPoints=%s, size=%s, graphicName=%s]";
return out.formatted(getClass().getSimpleName(),
name,
visible,
fillColor,
strokeColor,
strokeWidth,
indentedListString(indent, true, points, Object::toString),
numberOfPoints,
size,
graphicName);
}
}