Data class containing a bounding-object created by extruding a Contour along a vector. More...
#include <mitkExtrudedContour.h>
Public Types | |
typedef ExtrudedContour | Self |
typedef BoundingObject | Superclass |
typedef itk::SmartPointer< Self > | Pointer |
typedef itk::SmartPointer < const Self > | ConstPointer |
Public Member Functions | |
virtual const char * | GetClassName () const |
virtual mitk::ScalarType | GetVolume () |
virtual bool | IsInside (const Point3D &p) const |
virtual void | UpdateOutputInformation () |
Update the information for this BaseData (the geometry in particular) so that it can be used as an output of a BaseProcess. | |
virtual const mitk::Contour * | GetContour () |
Contour to extrude. | |
virtual void | SetContour (mitk::Contour *_arg) |
virtual const mitk::Vector3D & | GetVector () |
Vector to specify the direction of the extrusion. | |
virtual void | SetVector (const mitk::Vector3D &_arg) |
virtual bool | GetAutomaticVectorGeneration () const |
virtual void | SetAutomaticVectorGeneration (bool _arg) |
virtual void | AutomaticVectorGenerationOn () |
virtual void | AutomaticVectorGenerationOff () |
virtual const mitk::Vector3D & | GetRightVector () |
Optional vector to specify the orientation of the bounding-box. | |
virtual void | SetRightVector (const mitk::Vector3D &_arg) |
virtual const mitk::Geometry3D * | GetClippingGeometry () |
Optional geometry for clipping the extruded contour. | |
virtual void | SetClippingGeometry (mitk::Geometry3D *_arg) |
virtual unsigned long | GetMTime () const |
Get the modified time of the last change of the contents this data object or its geometry. | |
Static Public Member Functions | |
static Pointer | New () |
Protected Member Functions | |
ExtrudedContour () | |
virtual | ~ExtrudedContour () |
void | BuildSurface () |
void | BuildGeometry () |
Protected Attributes | |
mitk::Contour::Pointer | m_Contour |
mitk::Vector3D | m_Vector |
mitk::Vector3D | m_RightVector |
mitk::Geometry3D::Pointer | m_ClippingGeometry |
bool | m_AutomaticVectorGeneration |
vtkPolygon * | m_Polygon |
float | m_ProjectedContourBounds [6] |
mitk::PlaneGeometry::Pointer | m_ProjectionPlane |
float | m_Right [3] |
For fast projection on plane. | |
float | m_Down [3] |
float | m_Normal [3] |
float | m_Origin [3] |
vtkLinearExtrusionFilter * | m_ExtrusionFilter |
vtkTriangleFilter * | m_TriangleFilter |
vtkDecimatePro * | m_Decimate |
vtkLinearSubdivisionFilter * | m_SubdivisionFilter |
vtkPlanes * | m_ClippingBox |
vtkClipPolyData * | m_ClipPolyDataFilter |
itk::TimeStamp | m_LastCalculateExtrusionTime |
Data class containing a bounding-object created by extruding a Contour along a vector.
The m_Contour is extruded in the direction m_Vector until reaching m_ClippingGeometry.
Definition at line 45 of file mitkExtrudedContour.h.
typedef itk::SmartPointer<const Self> mitk::ExtrudedContour::ConstPointer |
Reimplemented from mitk::BoundingObject.
Definition at line 48 of file mitkExtrudedContour.h.
typedef itk::SmartPointer<Self> mitk::ExtrudedContour::Pointer |
Reimplemented from mitk::BoundingObject.
Definition at line 48 of file mitkExtrudedContour.h.
Reimplemented from mitk::BoundingObject.
Definition at line 48 of file mitkExtrudedContour.h.
Reimplemented from mitk::BoundingObject.
Definition at line 48 of file mitkExtrudedContour.h.
mitk::ExtrudedContour::ExtrudedContour | ( | ) | [protected] |
Definition at line 45 of file mitkExtrudedContour.cpp.
References mitk::BaseData::GetTimeSlicedGeometry(), mitk::TimeSlicedGeometry::Initialize(), m_ClippingBox, m_ClipPolyDataFilter, m_ExtrusionFilter, m_Polygon, m_ProjectionPlane, m_RightVector, m_SubdivisionFilter, m_TriangleFilter, m_Vector, and New().
: m_Contour(NULL), m_ClippingGeometry(NULL), m_AutomaticVectorGeneration(false) { GetTimeSlicedGeometry()->Initialize(1); FillVector3D(m_Vector, 0.0, 0.0, 1.0); m_RightVector.Fill(0.0); m_ExtrusionFilter = vtkLinearExtrusionFilter::New(); m_ExtrusionFilter->CappingOff(); m_ExtrusionFilter->SetExtrusionTypeToVectorExtrusion(); #if ((VTK_MAJOR_VERSION > 4) || ((VTK_MAJOR_VERSION==4) && (VTK_MINOR_VERSION>=4) )) double vtkvector[3]={0,0,1}; #else float vtkvector[3]={0,0,1}; #endif // set extrusion vector m_ExtrusionFilter->SetVector(vtkvector); m_TriangleFilter = vtkTriangleFilter::New(); m_TriangleFilter->SetInput(m_ExtrusionFilter->GetOutput()); m_SubdivisionFilter = vtkLinearSubdivisionFilter::New(); m_SubdivisionFilter->SetInput(m_TriangleFilter->GetOutput()); m_SubdivisionFilter->SetNumberOfSubdivisions(4); m_ClippingBox = vtkPlanes::New(); m_ClipPolyDataFilter = vtkClipPolyData::New(); m_ClipPolyDataFilter->SetInput(m_SubdivisionFilter->GetOutput()); m_ClipPolyDataFilter->SetClipFunction(m_ClippingBox); m_ClipPolyDataFilter->InsideOutOn(); m_Polygon = vtkPolygon::New(); m_ProjectionPlane = mitk::PlaneGeometry::New(); }
mitk::ExtrudedContour::~ExtrudedContour | ( | ) | [protected, virtual] |
Definition at line 84 of file mitkExtrudedContour.cpp.
{ m_ClipPolyDataFilter->Delete(); m_ClippingBox->Delete(); m_SubdivisionFilter->Delete(); m_TriangleFilter->Delete(); m_ExtrusionFilter->Delete(); m_Polygon->Delete(); }
virtual void mitk::ExtrudedContour::AutomaticVectorGenerationOff | ( | ) | [virtual] |
virtual void mitk::ExtrudedContour::AutomaticVectorGenerationOn | ( | ) | [virtual] |
void mitk::ExtrudedContour::BuildGeometry | ( | ) | [protected] |
Definition at line 228 of file mitkExtrudedContour.cpp.
References QuadProgPP::dist(), QuadProgPP::max(), and min.
{ if(m_Contour.IsNull()) return; // Initialize(1); Vector3D nullvector; nullvector.Fill(0.0); float xProj[3]; unsigned int i; unsigned int numPts = 20; //m_Contour->GetNumberOfPoints(); mitk::Contour::PathPointer path = m_Contour->GetContourPath(); mitk::Contour::PathType::InputType cstart = path->StartOfInput(); mitk::Contour::PathType::InputType cend = path->EndOfInput(); mitk::Contour::PathType::InputType cstep = (cend-cstart)/numPts; mitk::Contour::PathType::InputType ccur; // Part I: guarantee/calculate legal vectors m_Vector.Normalize(); itk2vtk(m_Vector, m_Normal); // check m_Vector if(mitk::Equal(m_Vector, nullvector) || m_AutomaticVectorGeneration) { if ( m_AutomaticVectorGeneration == false) itkWarningMacro("Extrusion vector is 0 ("<< m_Vector << "); trying to use normal of polygon"); vtkPoints *loopPoints = vtkPoints::New(); //mitk::Contour::PointsContainerIterator pointsIt = m_Contour->GetPoints()->Begin(); #if ((VTK_MAJOR_VERSION > 4) || ((VTK_MAJOR_VERSION==4) && (VTK_MINOR_VERSION>=4) )) double vtkpoint[3]; #else float vtkpoint[3]; #endif unsigned int i=0; for(i=0, ccur=cstart; i<numPts; ++i, ccur+=cstep) { itk2vtk(path->Evaluate(ccur), vtkpoint); loopPoints->InsertNextPoint(vtkpoint); } // Make sure points define a loop with a m_Normal vtkPolygon::ComputeNormal(loopPoints, m_Normal); loopPoints->Delete(); vtk2itk(m_Normal, m_Vector); if(mitk::Equal(m_Vector, nullvector)) { itkExceptionMacro("Cannot calculate normal of polygon"); } } // check m_RightVector if((mitk::Equal(m_RightVector, nullvector)) || (mitk::Equal(m_RightVector*m_Vector, 0.0)==false)) { if(mitk::Equal(m_RightVector, nullvector)) { itkDebugMacro("Right vector is 0. Calculating."); } else { itkWarningMacro("Right vector ("<<m_RightVector<<") not perpendicular to extrusion vector "<<m_Vector<<": "<<m_RightVector*m_Vector); } // calculate a legal m_RightVector if( mitk::Equal( m_Vector[1], 0.0f ) == false ) { FillVector3D( m_RightVector, 1.0f, -m_Vector[0]/m_Vector[1], 0.0f ); m_RightVector.Normalize(); } else { FillVector3D( m_RightVector, 0.0f, 1.0f, 0.0f ); } } // calculate down-vector VnlVector rightDV = m_RightVector.Get_vnl_vector(); rightDV.normalize(); vnl2vtk(rightDV, m_Right); VnlVector downDV = vnl_cross_3d( m_Vector.Get_vnl_vector(), rightDV ); downDV.normalize(); vnl2vtk(downDV, m_Down); // Part II: calculate plane as base for extrusion, project the contour // on this plane and store as polygon for IsInside test and BoundingBox calculation // initialize m_ProjectionPlane, yet with origin at 0 m_ProjectionPlane->InitializeStandardPlane(rightDV, downDV); // create vtkPolygon from contour and simultaneously determine 2D bounds of // contour projected on m_ProjectionPlane //mitk::Contour::PointsContainerIterator pointsIt = m_Contour->GetPoints()->Begin(); m_Polygon->Points->Reset(); m_Polygon->Points->SetNumberOfPoints(numPts); m_Polygon->PointIds->Reset(); m_Polygon->PointIds->SetNumberOfIds(numPts); mitk::Point2D pt2d; mitk::Point3D pt3d; mitk::Point2D min, max; min.Fill(ScalarTypeNumericTraits::max()); max.Fill(ScalarTypeNumericTraits::min()); xProj[2]=0.0; for(i=0, ccur=cstart; i<numPts; ++i, ccur+=cstep) { pt3d.CastFrom(path->Evaluate(ccur)); m_ProjectionPlane->Map(pt3d, pt2d); xProj[0]=pt2d[0]; if(pt2d[0]<min[0]) min[0]=pt2d[0]; if(pt2d[0]>max[0]) max[0]=pt2d[0]; xProj[1]=pt2d[1]; if(pt2d[1]<min[1]) min[1]=pt2d[1]; if(pt2d[1]>max[1]) max[1]=pt2d[1]; m_Polygon->Points->SetPoint(i, xProj); m_Polygon->PointIds->SetId(i, i); } // shift parametric origin to (0,0) for(i=0; i<numPts; ++i) { #if ((VTK_MAJOR_VERSION > 4) || ((VTK_MAJOR_VERSION==4) && (VTK_MINOR_VERSION>=4) )) double * pt = this->m_Polygon->Points->GetPoint(i); #else float * pt = this->m_Polygon->Points->GetPoint(i); #endif pt[0]-=min[0]; pt[1]-=min[1]; itkDebugMacro( << i << ": (" << pt[0] << "," << pt[1] << "," << pt[2] << ")" ); } this->m_Polygon->GetBounds(m_ProjectedContourBounds); //m_ProjectedContourBounds[4]=-1.0; m_ProjectedContourBounds[5]=1.0; // calculate origin (except translation along the normal) and bounds // of m_ProjectionPlane: // origin is composed of the minimum x-/y-coordinates of the polygon, // bounds from the extent of the polygon, both after projecting on the plane mitk::Point3D origin; m_ProjectionPlane->Map(min, origin); ScalarType bounds[6]={0, max[0]-min[0], 0, max[1]-min[1], 0, 1}; m_ProjectionPlane->SetBounds(bounds); m_ProjectionPlane->SetOrigin(origin); // Part III: initialize geometry if(m_ClippingGeometry.IsNotNull()) { ScalarType min_dist=ScalarTypeNumericTraits::max(), max_dist=ScalarTypeNumericTraits::min(), dist; unsigned char i; for(i=0; i<8; ++i) { dist = m_ProjectionPlane->SignedDistance( m_ClippingGeometry->GetCornerPoint(i) ); if(dist<min_dist) min_dist=dist; if(dist>max_dist) max_dist=dist; } //incorporate translation along the normal into origin origin = origin+m_Vector*min_dist; m_ProjectionPlane->SetOrigin(origin); bounds[5]=max_dist-min_dist; } else bounds[5]=20; itk2vtk(origin, m_Origin); mitk::TimeSlicedGeometry::Pointer timeGeometry = this->GetTimeSlicedGeometry(); mitk::Geometry3D::Pointer g3d = timeGeometry->GetGeometry3D( 0 ); assert( g3d.IsNotNull() ); g3d->SetBounds(bounds); g3d->SetIndexToWorldTransform(m_ProjectionPlane->GetIndexToWorldTransform()); g3d->TransferItkToVtkTransform(); timeGeometry->InitializeEvenlyTimed(g3d, 1); }
void mitk::ExtrudedContour::BuildSurface | ( | ) | [protected] |
Definition at line 172 of file mitkExtrudedContour.cpp.
{ if(m_Contour.IsNull()) { SetVtkPolyData(NULL); return; } // set extrusion contour vtkPolyData *polyData = vtkPolyData::New(); vtkCellArray *polys = vtkCellArray::New(); polys->InsertNextCell(m_Polygon->GetPointIds()); polyData->SetPoints(m_Polygon->GetPoints()); //float vtkpoint[3]; //unsigned int i, numPts = m_Polygon->GetNumberOfPoints(); //for(i=0; i<numPts; ++i) //{ // float * vtkpoint = this->m_Polygon->Points->GetPoint(i); // pointids[i]=loopPoints->InsertNextPoint(vtkpoint); //} //polys->InsertNextCell( i, pointids ); //delete [] pointids; //polyData->SetPoints( loopPoints ); polyData->SetPolys( polys ); polys->Delete(); m_ExtrusionFilter->SetInput(polyData); polyData->Delete(); // set extrusion scale factor m_ExtrusionFilter->SetScaleFactor(GetGeometry()->GetExtentInMM(2)); SetVtkPolyData(m_SubdivisionFilter->GetOutput()); //if(m_ClippingGeometry.IsNull()) //{ // SetVtkPolyData(m_SubdivisionFilter->GetOutput()); //} //else //{ // m_ClipPolyDataFilter->SetInput(m_SubdivisionFilter->GetOutput()); // mitk::BoundingBox::BoundsArrayType bounds=m_ClippingGeometry->GetBounds(); // m_ClippingBox->SetBounds(bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5]); // m_ClippingBox->SetTransform(GetGeometry()->GetVtkTransform()); // m_ClipPolyDataFilter->SetClipFunction(m_ClippingBox); // m_ClipPolyDataFilter->SetValue(0); // SetVtkPolyData(m_ClipPolyDataFilter->GetOutput()); //} m_LastCalculateExtrusionTime.Modified(); }
virtual bool mitk::ExtrudedContour::GetAutomaticVectorGeneration | ( | ) | const [virtual] |
virtual const char* mitk::ExtrudedContour::GetClassName | ( | ) | const [virtual] |
Reimplemented from mitk::BoundingObject.
virtual const mitk::Geometry3D* mitk::ExtrudedContour::GetClippingGeometry | ( | ) | [virtual] |
Optional geometry for clipping the extruded contour.
virtual const mitk::Contour* mitk::ExtrudedContour::GetContour | ( | ) | [virtual] |
Contour to extrude.
unsigned long mitk::ExtrudedContour::GetMTime | ( | ) | const [virtual] |
Get the modified time of the last change of the contents this data object or its geometry.
Reimplemented from mitk::BaseData.
Definition at line 392 of file mitkExtrudedContour.cpp.
{ unsigned long latestTime = Superclass::GetMTime(); if(m_Contour.IsNotNull()) { unsigned long localTime; localTime = m_Contour->GetMTime(); if(localTime > latestTime) latestTime = localTime; } return latestTime; }
virtual const mitk::Vector3D& mitk::ExtrudedContour::GetRightVector | ( | ) | [virtual] |
Optional vector to specify the orientation of the bounding-box.
virtual const mitk::Vector3D& mitk::ExtrudedContour::GetVector | ( | ) | [virtual] |
Vector to specify the direction of the extrusion.
mitk::ScalarType mitk::ExtrudedContour::GetVolume | ( | ) | [virtual] |
Reimplemented from mitk::BoundingObject.
Definition at line 152 of file mitkExtrudedContour.cpp.
{
return -1.0;
}
bool mitk::ExtrudedContour::IsInside | ( | const Point3D & | p ) | const [virtual] |
Definition at line 94 of file mitkExtrudedContour.cpp.
References QuadProgPP::dist().
{ #if ((VTK_MAJOR_VERSION > 4) || ((VTK_MAJOR_VERSION==4) && (VTK_MINOR_VERSION>=4) )) static double polygonNormal[3]={0.0,0.0,1.0}; #else static float polygonNormal[3]={0.0,0.0,1.0}; #endif // project point onto plane float xt[3]; itk2vtk(worldPoint, xt); xt[0] = worldPoint[0]-m_Origin[0]; xt[1] = worldPoint[1]-m_Origin[1]; xt[2] = worldPoint[2]-m_Origin[2]; float dist=xt[0]*m_Normal[0]+xt[1]*m_Normal[1]+xt[2]*m_Normal[2]; xt[0] -= dist*m_Normal[0]; xt[1] -= dist*m_Normal[1]; xt[2] -= dist*m_Normal[2]; #if ((VTK_MAJOR_VERSION > 4) || ((VTK_MAJOR_VERSION==4) && (VTK_MINOR_VERSION>=4) )) double x[3]; #else float x[3]; #endif x[0] = xt[0]*m_Right[0]+xt[1]*m_Right[1]+xt[2]*m_Right[2]; x[1] = xt[0]*m_Down[0] +xt[1]*m_Down[1] +xt[2]*m_Down[2]; x[2] = 0; #if ((VTK_MAJOR_VERSION > 4) || ((VTK_MAJOR_VERSION==4) && (VTK_MINOR_VERSION>=4) )) // determine whether it's in the selection loop and then evaluate point // in polygon only if absolutely necessary. if ( x[0] >= this->m_ProjectedContourBounds[0] && x[0] <= this->m_ProjectedContourBounds[1] && x[1] >= this->m_ProjectedContourBounds[2] && x[1] <= this->m_ProjectedContourBounds[3] && this->m_Polygon->PointInPolygon(x, m_Polygon->Points->GetNumberOfPoints(), ((vtkDoubleArray *)this->m_Polygon->Points->GetData())->GetPointer(0), (double*)const_cast<mitk::ExtrudedContour*>(this)->m_ProjectedContourBounds, polygonNormal) == 1 ) return true; else return false; #else // determine whether it's in the selection loop and then evaluate point // in polygon only if absolutely necessary. if ( x[0] >= this->m_ProjectedContourBounds[0] && x[0] <= this->m_ProjectedContourBounds[1] && x[1] >= this->m_ProjectedContourBounds[2] && x[1] <= this->m_ProjectedContourBounds[3] && this->m_Polygon->PointInPolygon(x, m_Polygon->Points->GetNumberOfPoints(), ((vtkFloatArray *)this->m_Polygon->Points->GetData())->GetPointer(0), const_cast<mitk::ExtrudedContour*>(this)->m_ProjectedContourBounds, polygonNormal) == 1 ) return true; else return false; #endif }
static Pointer mitk::ExtrudedContour::New | ( | ) | [static] |
Reimplemented from mitk::Surface.
Referenced by ExtrudedContour().
virtual void mitk::ExtrudedContour::SetAutomaticVectorGeneration | ( | bool | _arg ) | [virtual] |
virtual void mitk::ExtrudedContour::SetClippingGeometry | ( | mitk::Geometry3D * | _arg ) | [virtual] |
virtual void mitk::ExtrudedContour::SetContour | ( | mitk::Contour * | _arg ) | [virtual] |
Referenced by mitk::ExtrudedContourInteractor::ExecuteAction().
virtual void mitk::ExtrudedContour::SetRightVector | ( | const mitk::Vector3D & | _arg ) | [inline, virtual] |
Definition at line 71 of file mitkExtrudedContour.h.
virtual void mitk::ExtrudedContour::SetVector | ( | const mitk::Vector3D & | _arg ) | [inline, virtual] |
Definition at line 63 of file mitkExtrudedContour.h.
Referenced by mitk::ExtrudedContourInteractor::ExecuteAction().
void mitk::ExtrudedContour::UpdateOutputInformation | ( | ) | [virtual] |
Update the information for this BaseData (the geometry in particular) so that it can be used as an output of a BaseProcess.
This method is used in the pipeline mechanism to propagate information and initialize the meta data associated with a BaseData. Any implementation of this method in a derived class is assumed to call its source's BaseProcess::UpdateOutputInformation() which determines modified times, LargestPossibleRegions, and any extra meta data like spacing, origin, etc. Default implementation simply call's it's source's UpdateOutputInformation().
Reimplemented from mitk::Surface.
Definition at line 157 of file mitkExtrudedContour.cpp.
{ if ( this->GetSource() ) { this->GetSource()->UpdateOutputInformation(); } if(GetMTime() > m_LastCalculateExtrusionTime) { BuildGeometry(); BuildSurface(); } //if ( ( m_CalculateBoundingBox ) && ( m_PolyDataSeries.size() > 0 ) ) // CalculateBoundingBox(); }
bool mitk::ExtrudedContour::m_AutomaticVectorGeneration [protected] |
Definition at line 91 of file mitkExtrudedContour.h.
vtkPlanes* mitk::ExtrudedContour::m_ClippingBox [protected] |
Definition at line 118 of file mitkExtrudedContour.h.
Referenced by ExtrudedContour().
Definition at line 89 of file mitkExtrudedContour.h.
vtkClipPolyData* mitk::ExtrudedContour::m_ClipPolyDataFilter [protected] |
Definition at line 119 of file mitkExtrudedContour.h.
Referenced by ExtrudedContour().
Definition at line 86 of file mitkExtrudedContour.h.
vtkDecimatePro* mitk::ExtrudedContour::m_Decimate [protected] |
Definition at line 116 of file mitkExtrudedContour.h.
float mitk::ExtrudedContour::m_Down[3] [protected] |
Definition at line 105 of file mitkExtrudedContour.h.
vtkLinearExtrusionFilter* mitk::ExtrudedContour::m_ExtrusionFilter [protected] |
Definition at line 114 of file mitkExtrudedContour.h.
Referenced by ExtrudedContour().
itk::TimeStamp mitk::ExtrudedContour::m_LastCalculateExtrusionTime [protected] |
Definition at line 121 of file mitkExtrudedContour.h.
float mitk::ExtrudedContour::m_Normal[3] [protected] |
Definition at line 110 of file mitkExtrudedContour.h.
float mitk::ExtrudedContour::m_Origin[3] [protected] |
Definition at line 112 of file mitkExtrudedContour.h.
vtkPolygon* mitk::ExtrudedContour::m_Polygon [protected] |
Definition at line 93 of file mitkExtrudedContour.h.
Referenced by ExtrudedContour().
float mitk::ExtrudedContour::m_ProjectedContourBounds[6] [protected] |
Definition at line 98 of file mitkExtrudedContour.h.
Definition at line 101 of file mitkExtrudedContour.h.
Referenced by ExtrudedContour().
float mitk::ExtrudedContour::m_Right[3] [protected] |
For fast projection on plane.
Definition at line 104 of file mitkExtrudedContour.h.
mitk::Vector3D mitk::ExtrudedContour::m_RightVector [protected] |
Definition at line 88 of file mitkExtrudedContour.h.
Referenced by ExtrudedContour().
vtkLinearSubdivisionFilter* mitk::ExtrudedContour::m_SubdivisionFilter [protected] |
Definition at line 117 of file mitkExtrudedContour.h.
Referenced by ExtrudedContour().
vtkTriangleFilter* mitk::ExtrudedContour::m_TriangleFilter [protected] |
Definition at line 115 of file mitkExtrudedContour.h.
Referenced by ExtrudedContour().
mitk::Vector3D mitk::ExtrudedContour::m_Vector [protected] |
Definition at line 87 of file mitkExtrudedContour.h.
Referenced by ExtrudedContour().