本类是线段、圆形、矩形、贝塞尔曲线等2D图形的基类。注意,本类文档中已经给出其子类必须实现的函数。
PlanarFigures的行为和外观由属性控制。详细属性列表参见mitk::PlanarFigureMapper2D。以下列出几个常见属性:
- “selected”: planar 被选中时为true。
- “planarfigure.ishovering”:如设为true,则鼠标悬停在planar上时有对应行为。
- “planarfigure.iseditable”: 默认为true。如设为
true,则planar figure可以被编辑。否则,只能被选中,不能拖动控制点。 - “planarfigure.isextendable”: 默认为false。如设为true,则可以在控制点列表中随意插入新的控制点。
设置属性可以使用planarfigure->setPropterty()。
创建PlanarFigure
以下代码仅供说明问题:
//首先头两个控制点应该这样添加
mitk::PlanarCCRCurve::Pointer figure=mitk::PlanarCCRCurve::New();
figure->PlaceFigure(m_ControlPoints[0]);
figure->SetControlPoint(1,m_ControlPoints[1]);
//如果有更多的控制点则这样添加,但不能超过设定的控制点数量上界
if (m_NumOfControlPoints>2)//控制点多于两个,则添加进去
{
for (unsigned int i=2;i<m_ControlPoints.size();i++)
{
figure->AddControlPoint(m_ControlPoints[i],i);
}
}
本类头文件说明:
class MitkPlanarFigure_EXPORT PlanarFigure : public BaseData
{
public:
mitkClassMacro( PlanarFigure, BaseData )
itkCloneMacro( Self )
typedef Point2D PolyLineElement;
typedef itk::VectorContainer< unsigned long, bool> BoolContainerType;
typedef std::deque< Point2D > ControlPointListType;
typedef std::vector< PolyLineElement > PolyLineType;
/** \brief Sets the 2D geometry on which this figure will be placed.
*
* In most cases, this is a Geometry already owned by another object, e.g.
* describing the slice of the image on which measurements will be
* performed.
*/
virtual void SetPlaneGeometry( mitk::PlaneGeometry *geometry );
/** \brief Returns (previously set) 2D geometry of this figure. */
virtual const PlaneGeometry *GetPlaneGeometry() const;
/** \brief True if the planar figure is closed.
*
* Default is false. The "closed" boolean property must be set in sub-classes. */
virtual bool IsClosed() const;
/** \brief True if the planar figure has been placed (and can be
* displayed/interacted with). */
virtual bool IsPlaced() const { return m_FigurePlaced; };
/** \brief Place figure at the given point (in 2D index coordinates) onto
* the given 2D geometry.
*
* By default, the first two control points of the figure are set to the
* passed point. Further points can be set via AddControlPoint(), if the
* current number of control points is below the maximum number of control
* points.
*
* Can be re-implemented in sub-classes as needed.
*/
virtual void PlaceFigure( const Point2D& point );
/**
* 添加/插入新控制点。
* 在指定的index处插入新的结点。如果index为-1,或大于当前控制点的数量,
* 插在此处后,其后的点需要后移。控制点数量达到上界后无法添加新点(可用
* GetMaximumNumberOfControlPoints()查询上界)。
*/
virtual bool AddControlPoint( const Point2D& point, int index = -1 );
virtual bool SetControlPoint( unsigned int index, const Point2D& point, bool createIfDoesNotExist = false);
virtual bool SetCurrentControlPoint( const Point2D& point );
/** \brief Returns the current number of 2D control points defining this figure. */
unsigned int GetNumberOfControlPoints() const;
/** \brief 返回控制点数量下界
*
* Must be implemented in sub-classes.
*/
virtual unsigned int GetMinimumNumberOfControlPoints() const = 0;
/** \brief 返回控制点数量上界(如三角形必须为3)
*
* Must be implemented in sub-classes.
*/
virtual unsigned int GetMaximumNumberOfControlPoints() const = 0;
/** \brief 选中当前活跃的点 */
virtual bool SelectControlPoint( unsigned int index );
/** \brief 取消选中。当前没有活跃控制点 */
virtual bool DeselectControlPoint();
/** \brief 返回当前被选中的控制点. */
virtual int GetSelectedControlPoint() const { return m_SelectedControlPoint; }
/** \brief 返回指定控制点的2D坐标*/
Point2D GetControlPoint( unsigned int index ) const;
/** \brief 返回指定控制点的世界坐标 */
Point3D GetWorldControlPoint( unsigned int index ) const;
/** \brief 返回代表当前planar的折线
* (for rendering, measurements, etc.). */
const PolyLineType GetPolyLine(unsigned int index);
/** \brief 返回代表当前planar的折线
* (for rendering, measurments, etc.). */
const PolyLineType GetPolyLine(unsigned int index) const;
/** \brief 辅助折线
* (for text, angles, etc.). */
const PolyLineType GetHelperPolyLine( unsigned int index, double mmPerDisplayUnit, unsigned int displayHeight );
/** \brief Sets the position of the PreviewControlPoint. Automatically sets it visible.*/
void SetPreviewControlPoint( const Point2D& point );
/** \brief Marks the PreviewControlPoint as invisible.*/
void ResetPreviewContolPoint();
/** \brief Returns whether or not the PreviewControlPoint is visible.*/
bool IsPreviewControlPointVisible();
/** \brief Returns the coordinates of the PreviewControlPoint. */
Point2D GetPreviewControlPoint();
/** 返回当前planar的特征数(面积、半径等)*/
virtual unsigned int GetNumberOfFeatures() const;
/** 返回指定特征的名字
const char *GetFeatureName( unsigned int index ) const;
/** 指定特征的物理单位(毫米等) */
const char *GetFeatureUnit( unsigned int index ) const;
/** 返回指定特征的值(长度,半径等)*/
double GetQuantity( unsigned int index ) const;
/** 如果指定特征存在且被激活(例如非闭合折线的面积就是未被激活的),返回真*/
bool IsFeatureActive( unsigned int index ) const;
/** 如果index指定的特征存在且可见,为真*/
bool IsFeatureVisible( unsigned int index ) const;
/** 指定的特征是否显示在渲染窗口里,叠加在其他图片上方*/
void SetFeatureVisible( unsigned int index, bool visible );
/** 计算planar里面所有特征的值 */
virtual void EvaluateFeatures();
/** 继承自父类 */
virtual void UpdateOutputInformation();
/** 继承自父类 */
virtual void SetRequestedRegionToLargestPossibleRegion();
/** 继承自父类 */
virtual bool RequestedRegionIsOutsideOfTheBufferedRegion();
/** 继承自父类 */
virtual bool VerifyRequestedRegion();
/** 继承自父类 */
virtual void SetRequestedRegion( const itk::DataObject *data);
/** 返回当前折线的数量,意思就是你的planar由几条线组成 */
virtual unsigned short GetPolyLinesSize();
/** 返回当前helperpolyline的数量 */
virtual unsigned short GetHelperPolyLinesSize();
/** 返回index指定的helper polyline是否已被渲染显示 */
virtual bool IsHelperToBePainted(unsigned int index);
/** 当一个控制点被选中时,如果planar被重设为“add points”模式,则返回真
* 默认值为false。子类可重写这个方法,如果需要可以调用reset / initialization声明*/
virtual bool ResetOnPointSelect();
/** 从列表中删除指定控制点 */
virtual void RemoveControlPoint( unsigned int index );
/** 删除列表最后一个控制点*/
virtual void RemoveLastControlPoint();
/** 方便子类能够对控制点进行空间约束(如不让其超出图像边界等)
*子类可重写这个方法,在空间上对控制点进行约束。
*默认情况下,这些点受图像边界约束
*/
virtual Point2D ApplyControlPointConstraints( unsigned int /*index*/, const Point2D& point );
/**
* 对比两个planar对象。
* 注意:所有子类都应按照自己的方式重载本方法。
*/
virtual bool Equals(const mitk::PlanarFigure& other) const;
protected:
PlanarFigure();
virtual ~PlanarFigure();
PlanarFigure(const Self& other);
/** 初始化控制点数量*/
void ResetNumberOfControlPoints( int numberOfControlPoints );
/** 在planar的特征数组中添加特征(周长,半径,角度,面积等),并返回该特征的ID(整数)。
* 应在在子类构造器中调用。*/
virtual unsigned int AddFeature( const char *featureName, const char *unitName );
/** 内部方法:设置指定特征的名字 */
void SetFeatureName( unsigned int index, const char *featureName );
/** 内部方法:设置指定特征的物理单位 */
void SetFeatureUnit( unsigned int index, const char *unitName );
/** 内部方法:设置指定特征的值 */
void SetQuantity( unsigned int index, double quantity );
/** 内部方法:将指定特征设为激活 */
void ActivateFeature( unsigned int index );
/** 内部方法:将指定特征设为未激活*/
void DeactivateFeature( unsigned int index );
/** 生成planar figure的折线
* 必须在子类中重载 */
virtual void GeneratePolyLine() = 0;
/** 生成辅助折线,缩放时其size不变。
* 必须在子类中重载 */
virtual void GenerateHelperPolyLine(double mmPerDisplayUnit, unsigned int displayHeight) = 0;
/** 计算所有特征的值
* 必须在子类中重载 */
virtual void EvaluateFeaturesInternal() = 0;
/** \brief Initializes the TimeGeometry describing the (time-resolved)
* geometry of this figure. Note that each time step holds one PlaneGeometry.
*/
virtual void InitializeTimeGeometry( unsigned int timeSteps = 1 );
/** 指定PolyLines的数量 */
void SetNumberOfPolyLines( unsigned int numberOfPolyLines );
/** 添加一个点到折线尾部。一般程序中每次添加index都为0,它的作用? */
void AppendPointToPolyLine( unsigned int index, PolyLineElement element );
/** 清除PolyLine列表。一般在重新计算折线时调用 */
void ClearPolyLines();
/** HelperPolyLines的数量*/
void SetNumberOfHelperPolyLines( unsigned int numberOfHelperPolyLines );
/** 在HelperPolyLine列表尾部添加一个点 # index */
void AppendPointToHelperPolyLine( unsigned int index, PolyLineElement element );
/** 清除HelperPolyLines列表。一般在重新计算HelperPolyLine时调用*/
void ClearHelperPolyLines();
virtual void PrintSelf( std::ostream& os, itk::Indent indent ) const;
ControlPointListType m_ControlPoints;
unsigned int m_NumberOfControlPoints;
// 当前被选中的控制点;-1表示没有点被选中
int m_SelectedControlPoint;
std::vector<PolyLineType> m_PolyLines;
std::vector<PolyLineType> m_HelperPolyLines;
BoolContainerType::Pointer m_HelperPolyLinesToBePainted;
// 该点储存一个额外“控制点”的坐标。这个点是当鼠标悬停在palar figure上且'planarfigure.isextendable'设为真时生成的,并不是真的控制点。
Point2D m_PreviewControlPoint;
bool m_PreviewControlPointVisible;
bool m_FigurePlaced;
private:
// not implemented to prevent PlanarFigure::New() calls which would create an itk::Object.
static Pointer New();
struct Feature
{
Feature( const char *name, const char *unit )
: Name( name ), Unit( unit ), Quantity( 0.0 ), Active( true ), Visible( true )
{
}
std::string Name;
std::string Unit;
double Quantity;
bool Active;
bool Visible;
};
virtual itk::LightObject::Pointer InternalClone() const = 0;
PlaneGeometry *m_PlaneGeometry;
bool m_PolyLineUpToDate;
bool m_HelperLinesUpToDate;
bool m_FeaturesUpToDate;
// Vector of features available for this geometric figure
typedef std::vector< Feature > FeatureVectorType;
FeatureVectorType m_Features;
unsigned long m_FeaturesMTime;
// this pair is used to store the mmInDisplayUnits (m_DisplaySize.first) and the displayHeight (m_DisplaySize.second)
// that the helperPolyLines have been calculated for.
// It's used to determine whether or not GetHelperPolyLine() needs to recalculate the HelperPolyLines.
std::pair<double, unsigned int> m_DisplaySize;
};
MITK_CORE_EXPORT bool Equal( const mitk::PlanarFigure& leftHandSide, const mitk::PlanarFigure& rightHandSide, ScalarType eps, bool verbose );
} // namespace mitk