us.ihmc.scs2.definition.yoGraphic.YoGraphicPointcloud3DDefinition 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.YoTuple3DDefinition;
/**
* A {@code YoGraphicPointcloud3DDefinition} is a template for creating multiple 3D points and which
* components can be backed by {@code YoVariable}s.
*
*
* The {@code YoGraphicPointcloud3DDefinition} 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 YoGraphicPointcloud3DDefinition extends YoGraphic3DDefinition
{
/** 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 spheres, 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:
*
* - "sphere":
*
* - "cube":
*
* - "tetrahedron":
*
* - "icosahedron":
*
*
*/
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 YoGraphicPointcloud3DDefinition()
{
registerListField("points", this::getPoints, this::setPoints, "p", Object::toString, YoTuple3DDefinition::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 spheres, 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 spheres, 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:
*
* - "sphere":
*
* - "cube":
*
* - "tetrahedron":
*
* - "icosahedron":
*
*
*
* @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 YoGraphicPointcloud3DDefinition 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, color=%s, points=%s, numberOfPoints=%s, size=%s, graphicName=%s]";
return out.formatted(getClass().getSimpleName(),
name,
visible,
color,
indentedListString(indent, true, points, Object::toString),
numberOfPoints,
size,
graphicName);
}
}