00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date$ 00006 Version: $Revision$ 00007 00008 Copyright (c) German Cancer Research Center, Division of Medical and 00009 Biological Informatics. All rights reserved. 00010 See MITKCopyright.txt or https://www.mitk.org/copyright.html for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 00018 #include "mitkPointSetToCurvedGeometryFilter.h" 00019 #include "mitkThinPlateSplineCurvedGeometry.h" 00020 #include "mitkPlaneGeometry.h" 00021 #include "mitkImage.h" 00022 #include "mitkTimeSlicedGeometry.h" 00023 #include "mitkDataNode.h" 00024 #include "mitkGeometryData.h" 00025 #include "mitkGeometry2DData.h" 00026 #include "mitkProperties.h" 00027 #include "itkMesh.h" 00028 #include "itkPointSet.h" 00029 00030 mitk::PointSetToCurvedGeometryFilter::PointSetToCurvedGeometryFilter() 00031 { 00032 m_ProjectionMode = YZPlane; 00033 m_PCAPlaneCalculator = mitk::PlaneFit::New(); 00034 m_ImageToBeMapped = NULL; 00035 m_Sigma = 1000; 00036 mitk::Geometry2DData::Pointer output = static_cast<mitk::Geometry2DData*> ( this->MakeOutput ( 0 ).GetPointer() ); 00037 output->Initialize(); 00038 Superclass::SetNumberOfRequiredOutputs ( 1 ); 00039 Superclass::SetNthOutput ( 0, output.GetPointer() ); 00040 } 00041 00042 00043 00044 mitk::PointSetToCurvedGeometryFilter::~PointSetToCurvedGeometryFilter() 00045 {} 00046 00047 void mitk::PointSetToCurvedGeometryFilter::GenerateOutputInformation() 00048 { 00049 mitk::PointSet::ConstPointer input = this->GetInput(); 00050 mitk::Geometry2DData::Pointer output = dynamic_cast<mitk::Geometry2DData*> ( this->GetOutput() ); 00051 00052 if ( input.IsNull() ) 00053 itkGenericExceptionMacro ( "Input point set is NULL!" ); 00054 00055 if ( input->GetTimeSlicedGeometry()->GetTimeSteps() != 1 ) 00056 itkWarningMacro ( "More than one time step is not yet supported!" ); 00057 00058 if ( output.IsNull() ) 00059 itkGenericExceptionMacro ( "Output is NULL!" ); 00060 00061 if ( m_ImageToBeMapped.IsNull() ) 00062 itkGenericExceptionMacro ( "Image to be mapped is NULL!" ); 00063 00064 bool update = false; 00065 if ( output->GetGeometry() == NULL || output->GetGeometry2D() == NULL || output->GetTimeSlicedGeometry() == NULL ) 00066 update = true; 00067 if ( ( ! update ) && ( output->GetTimeSlicedGeometry()->GetTimeSteps() != input->GetTimeSlicedGeometry()->GetTimeSteps() ) ) 00068 update = true; 00069 if ( update ) 00070 { 00071 mitk::ThinPlateSplineCurvedGeometry::Pointer curvedGeometry = mitk::ThinPlateSplineCurvedGeometry::New(); 00072 output->SetGeometry(curvedGeometry); 00073 00074 /* 00075 mitk::TimeSlicedGeometry::Pointer timeGeometry = mitk::TimeSlicedGeometry::New(); 00076 mitk::ThinPlateSplineCurvedGeometry::Pointer curvedGeometry = mitk::ThinPlateSplineCurvedGeometry::New(); 00077 00078 timeGeometry->InitializeEvenlyTimed ( curvedGeometry, input->GetPointSetSeriesSize() ); 00079 00080 for ( unsigned int t = 1; t < input->GetPointSetSeriesSize(); ++t ) 00081 { 00082 mitk::ThinPlateSplineCurvedGeometry::Pointer tmpCurvedGeometry = mitk::ThinPlateSplineCurvedGeometry::New(); 00083 timeGeometry->SetGeometry3D ( tmpCurvedGeometry.GetPointer(), t ); 00084 } 00085 output->SetGeometry ( timeGeometry ); 00086 output->SetGeometry2D ( curvedGeometry ); // @FIXME SetGeometry2D of mitk::Geometry2DData reinitializes the TimeSlicedGeometry to 1 time step 00087 */ 00088 } 00089 } 00090 00091 void mitk::PointSetToCurvedGeometryFilter::GenerateData() 00092 { 00093 mitk::PointSet::ConstPointer input = this->GetInput(); 00094 mitk::GeometryData::Pointer output = this->GetOutput(); 00095 00096 // 00097 // check preconditions 00098 // 00099 if ( input.IsNull() ) 00100 itkGenericExceptionMacro ( "Input point set is NULL!" ); 00101 if ( output.IsNull() ) 00102 itkGenericExceptionMacro ( "output geometry data is NULL!" ); 00103 if ( output->GetTimeSlicedGeometry() == NULL ) 00104 itkGenericExceptionMacro ( "Output time sliced geometry is NULL!" ); 00105 if ( output->GetTimeSlicedGeometry()->GetGeometry3D ( 0 ) == NULL ) 00106 itkGenericExceptionMacro ( "Output geometry3d is NULL!" ); 00107 mitk::ThinPlateSplineCurvedGeometry::Pointer curvedGeometry = dynamic_cast<mitk::ThinPlateSplineCurvedGeometry*> ( output->GetTimeSlicedGeometry()->GetGeometry3D ( 0 ) ); 00108 if ( curvedGeometry.IsNull() ) 00109 itkGenericExceptionMacro ( "Output geometry3d is not an instance of mitk::ThinPlateSPlineCurvedGeometry!" ); 00110 if ( m_ImageToBeMapped.IsNull() ) 00111 itkGenericExceptionMacro ( "Image to be mapped is NULL!" ); 00112 00113 // 00114 // initialize members if needed 00115 // 00116 if ( m_XYPlane.IsNull() || m_XZPlane.IsNull() || m_YZPlane.IsNull() ) 00117 { 00118 m_ImageToBeMapped->UpdateOutputInformation(); 00119 const mitk::Geometry3D* imageGeometry = m_ImageToBeMapped->GetUpdatedGeometry(); 00120 imageGeometry = m_ImageToBeMapped->GetUpdatedGeometry(); 00121 m_XYPlane = mitk::PlaneGeometry::New(); 00122 m_XZPlane = mitk::PlaneGeometry::New(); 00123 m_YZPlane = mitk::PlaneGeometry::New(); 00124 m_XYPlane->InitializeStandardPlane ( imageGeometry, mitk::PlaneGeometry::Transversal ); 00125 m_YZPlane->InitializeStandardPlane ( imageGeometry, mitk::PlaneGeometry::Sagittal ); 00126 m_XZPlane->InitializeStandardPlane ( imageGeometry, mitk::PlaneGeometry::Frontal ); 00127 } 00128 if ( m_PlaneLandmarkProjector.IsNull() ) 00129 { 00130 m_PlaneLandmarkProjector = mitk::PlaneLandmarkProjector::New(); 00131 m_SphereLandmarkProjector = mitk::SphereLandmarkProjector::New(); 00132 } 00133 00134 // 00135 // set up geometry according to the current settings 00136 // 00137 if ( m_ProjectionMode == Sphere ) 00138 { 00139 curvedGeometry->SetLandmarkProjector ( m_SphereLandmarkProjector ); 00140 } 00141 else 00142 { 00143 if ( m_ProjectionMode == XYPlane ) 00144 m_PlaneLandmarkProjector->SetProjectionPlane ( m_XYPlane ); 00145 else if ( m_ProjectionMode == XZPlane ) 00146 m_PlaneLandmarkProjector->SetProjectionPlane ( m_XZPlane ); 00147 else if ( m_ProjectionMode == YZPlane ) 00148 m_PlaneLandmarkProjector->SetProjectionPlane ( m_YZPlane ); 00149 else if ( m_ProjectionMode == PCAPlane ) 00150 { 00151 itkExceptionMacro ( "PCAPlane not yet implemented!" ); 00152 m_PCAPlaneCalculator->SetInput ( input ); 00153 m_PCAPlaneCalculator->Update(); 00154 m_PlaneLandmarkProjector->SetProjectionPlane ( dynamic_cast<mitk::PlaneGeometry*> ( m_PCAPlaneCalculator->GetOutput() ) ); 00155 } 00156 else 00157 itkExceptionMacro ( "Unknown projection mode" ); 00158 00159 curvedGeometry->SetLandmarkProjector ( m_PlaneLandmarkProjector ); 00160 } 00161 //curvedGeometry->SetReferenceGeometry( m_ImageToBeMapped->GetGeometry() ); 00162 curvedGeometry->SetTargetLandmarks ( input->GetPointSet ( 0 )->GetPoints() ); 00163 curvedGeometry->SetSigma ( m_Sigma ); 00164 curvedGeometry->ComputeGeometry(); 00165 curvedGeometry->SetOversampling ( 1.0 ); 00166 00167 } 00168 00169 mitk::GeometryDataSource::DataObjectPointer mitk::PointSetToCurvedGeometryFilter::MakeOutput ( unsigned int ) 00170 { 00171 return static_cast<itk::DataObject*> ( mitk::Geometry2DData::New().GetPointer() ); 00172 } 00173 00174 00175 void mitk::PointSetToCurvedGeometryFilter::SetDefaultCurvedGeometryProperties ( mitk::DataNode* node ) 00176 { 00177 if ( node == NULL ) 00178 { 00179 itkGenericOutputMacro ( "Warning: node is NULL!" ); 00180 return; 00181 } 00182 node->SetIntProperty ( "xresolution", 50 ); 00183 node->SetIntProperty ( "yresolution", 50 ); 00184 node->SetProperty ( "name", mitk::StringProperty::New ( "Curved Plane" ) ); 00185 // exclude extent of this plane when calculating DataStorage bounding box 00186 node->SetProperty ( "includeInBoundingBox", mitk::BoolProperty::New ( false ) ); 00187 }