Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "mitkPlanesPerpendicularToLinesFilter.h"
00019
00020 #include <vnl/vnl_cross.h>
00021 #include <vnl/vnl_quaternion.h>
00022 #include <vnl/vnl_quaternion.txx>
00023
00024 mitk::PlanesPerpendicularToLinesFilter::PlanesPerpendicularToLinesFilter()
00025 : m_Plane(NULL), m_UseAllPoints(false), m_CreatedGeometries(NULL), normal(3), targetRight(3)
00026 {
00027 m_CreatedGeometries = mitk::SlicedGeometry3D::New();
00028 }
00029
00030 mitk::PlanesPerpendicularToLinesFilter::~PlanesPerpendicularToLinesFilter()
00031 {
00032 }
00033
00034 void mitk::PlanesPerpendicularToLinesFilter::GenerateOutputInformation()
00035 {
00036 mitk::Mesh::ConstPointer input = this->GetInput();
00037 mitk::GeometryData::Pointer output = this->GetOutput();
00038
00039 itkDebugMacro(<<"GenerateOutputInformation()");
00040
00041 if(input.IsNull()) return;
00042
00043 output->SetGeometry(m_CreatedGeometries);
00044 }
00045
00046 void mitk::PlanesPerpendicularToLinesFilter::CreatePlane(const mitk::Point3D& curr)
00047 {
00048 int j;
00049 for(j=0;j<3;++j)
00050 normal[j] = last[j]-curr[j];
00051 normal.normalize();
00052
00053 down = vnl_cross_3d(normal, targetRight);
00054 down.normalize();
00055 right = vnl_cross_3d(down, normal);
00056 right.normalize();
00057
00058 itk2vtk(last.Get_vnl_vector()-right*halfWidthInMM-down*halfHeightInMM, origin);
00059 right *= targetSpacing[0];
00060 down *= targetSpacing[1];
00061 normal *= targetSpacing[2];
00062
00063 mitk::Matrix3D matrix;
00064 matrix.GetVnlMatrix().set_column(0, right);
00065 matrix.GetVnlMatrix().set_column(1, down);
00066 matrix.GetVnlMatrix().set_column(2, normal);
00067
00068 PlaneGeometry::Pointer plane = PlaneGeometry::New();
00069 plane->GetIndexToWorldTransform()->SetMatrix(matrix);
00070 plane->SetOrigin(origin);
00071 plane->SetBounds(bounds);
00072
00073 planes.push_back(plane);
00074
00075 last = curr;
00076 }
00077
00078 void mitk::PlanesPerpendicularToLinesFilter::GenerateData()
00079 {
00080 mitk::Mesh::ConstPointer input = this->GetInput();
00081 mitk::GeometryData::Pointer output = this->GetOutput();
00082
00083 if(m_Plane.IsNotNull())
00084 {
00085 targetRight = m_Plane->GetMatrixColumn(0);
00086 targetSpacing = m_Plane->GetSpacing();
00087 bounds = m_Plane->GetBoundingBox()->GetBounds();
00088 halfWidthInMM = m_Plane->GetExtentInMM(0)*0.5;
00089 halfHeightInMM = m_Plane->GetExtentInMM(1)*0.5;
00090 }
00091 else
00092 {
00093 FillVector3D(targetRight, 1.0, 0.0, 0.0);
00094 targetSpacing.Fill(1.0);
00095 halfWidthInMM=halfHeightInMM=100.0;
00096 ScalarType stdBounds[6] = {0.0, 2.0*halfWidthInMM, 0.0, 2.0*halfHeightInMM, 0.0, 0.0};
00097 bounds = stdBounds;
00098 }
00099
00100 if(m_UseAllPoints==false)
00101 {
00102 int i, size;
00103
00104 Mesh::ConstCellIterator cellIt, cellEnd;
00105 cellEnd = input->GetMesh()->GetCells()->End();
00106 for( cellIt = input->GetMesh()->GetCells()->Begin(); cellIt != cellEnd; ++cellIt )
00107 {
00108 Mesh::CellType& cell = *cellIt->Value();
00109
00110 Mesh::PointIdIterator ptIt, ptEnd;
00111 ptEnd = cell.PointIdsEnd();
00112
00113 size=cell.GetNumberOfPoints();
00114 if(size<=1)
00115 continue;
00116
00117 ptIt = cell.PointIdsBegin();
00118 last = input->GetPoint(*ptIt);
00119 ++ptIt;
00120 for(i=1;i<size;++i, ++ptIt)
00121 {
00122 CreatePlane(input->GetPoint(*ptIt));
00123 }
00124 }
00125 }
00126 else
00127 {
00128
00129 mitk::PointSet::PointsConstIterator it, pend = input->GetPointSet()->GetPoints()->End();
00130 it=input->GetPointSet()->GetPoints()->Begin();
00131 last = it.Value();
00132 ++it;
00133 for(;it!=pend;++it)
00134 {
00135 CreatePlane(it.Value());
00136 }
00137 }
00138
00139 if(planes.size()>0)
00140 {
00141
00142 m_CreatedGeometries->Initialize(planes.size()+1);
00143
00144
00145 PlaneGeometry::Pointer plane = static_cast<PlaneGeometry*>((*planes.rbegin())->Clone().GetPointer());
00146 itk2vtk(last.Get_vnl_vector()-right*halfWidthInMM-down*halfHeightInMM, origin);
00147 plane->SetOrigin(origin);
00148 m_CreatedGeometries->SetGeometry2D(plane, planes.size());
00149
00150
00151 int s;
00152 for(s=0; planes.empty()==false; planes.pop_front(), ++s)
00153 {
00154 m_CreatedGeometries->SetGeometry2D(planes.front(), s);
00155 }
00156
00157 m_CreatedGeometries->SetEvenlySpaced(false);
00158
00159 if(m_FrameGeometry.IsNotNull())
00160 {
00161 m_CreatedGeometries->SetIndexToWorldTransform(m_FrameGeometry->GetIndexToWorldTransform());
00162 m_CreatedGeometries->SetBounds(m_FrameGeometry->GetBounds());
00163 m_CreatedGeometries->SetReferenceGeometry(m_FrameGeometry);
00164 }
00165 }
00166
00167 output->SetGeometry(m_CreatedGeometries);
00168 }
00169
00170 void mitk::PlanesPerpendicularToLinesFilter::SetPlane(const mitk::PlaneGeometry* aPlane)
00171 {
00172 if(aPlane!=NULL)
00173 {
00174 m_Plane = static_cast<mitk::PlaneGeometry*>(aPlane->Clone().GetPointer());
00175 }
00176 else
00177 {
00178 if(m_Plane.IsNull())
00179 return;
00180 m_Plane=NULL;
00181 }
00182 Modified();
00183 }
00184
00185 const mitk::Mesh *mitk::PlanesPerpendicularToLinesFilter::GetInput(void)
00186 {
00187 if (this->GetNumberOfInputs() < 1)
00188 {
00189 return 0;
00190 }
00191
00192 return static_cast<const mitk::Mesh * >
00193 (this->ProcessObject::GetInput(0) );
00194 }
00195
00196 void mitk::PlanesPerpendicularToLinesFilter::SetInput(const mitk::Mesh *input)
00197 {
00198
00199 this->ProcessObject::SetNthInput(0,
00200 const_cast< mitk::Mesh * >( input ) );
00201 }
00202
00203 void mitk::PlanesPerpendicularToLinesFilter::SetFrameGeometry(const mitk::Geometry3D* frameGeometry)
00204 {
00205 if((frameGeometry != NULL) && (frameGeometry->IsValid()))
00206 {
00207 m_FrameGeometry = static_cast<mitk::Geometry3D*>(frameGeometry->Clone().GetPointer());
00208 }
00209 else
00210 {
00211 m_FrameGeometry = NULL;
00212 }
00213 }