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 "mitkContourSetToPointSetFilter.h" 00019 00020 #include <mitkPointOperation.h> 00021 #include <mitkInteractionConst.h> 00022 00023 mitk::ContourSetToPointSetFilter::ContourSetToPointSetFilter() 00024 { 00025 OutputType::Pointer output = dynamic_cast<OutputType*> ( this->MakeOutput( 0 ).GetPointer() ); 00026 this->SetNumberOfRequiredInputs(1); 00027 this->SetNumberOfOutputs( 1 ); 00028 this->SetNthOutput(0, output.GetPointer()); 00029 m_Frequency = 5; 00030 } 00031 00032 mitk::ContourSetToPointSetFilter::~ContourSetToPointSetFilter() 00033 { 00034 } 00035 00036 void mitk::ContourSetToPointSetFilter::GenerateOutputInformation() 00037 { 00038 00039 } 00040 00041 void mitk::ContourSetToPointSetFilter::GenerateData() 00042 { 00043 mitk::ContourSet* input = (mitk::ContourSet*) (this->GetInput()); 00044 mitk::PointSet::Pointer output = this->GetOutput(); 00045 00046 mitk::ContourSet::ContourVectorType contourVec = input->GetContours(); 00047 mitk::ContourSet::ContourIterator contourIt = contourVec.begin(); 00048 unsigned int pointId = 0; 00049 00050 while ( contourIt != contourVec.end() ) 00051 { 00052 mitk::Contour* nextContour = (mitk::Contour*) (*contourIt).second; 00053 00054 mitk::Contour::InputType idx = nextContour->GetContourPath()->StartOfInput(); 00055 mitk::Contour::OutputType point; 00056 mitk::Contour::InputType end = nextContour->GetContourPath()->EndOfInput(); 00057 if (end > 50000) end = 0; 00058 00059 while ( idx <= end ) 00060 { 00061 point = nextContour->GetContourPath()->Evaluate(idx); 00062 Contour::BoundingBoxType::PointType p; 00063 p.CastFrom(point); 00064 mitk::PointOperation popInsert( mitk::OpINSERT, p, pointId++ ); 00065 mitk::PointOperation popDeactivate( mitk::OpDESELECTPOINT, p , pointId++ ); 00066 output->ExecuteOperation( &popInsert ); 00067 output->ExecuteOperation( &popDeactivate ); 00068 00069 idx+=m_Frequency; 00070 } 00071 contourIt++; 00072 } 00073 } 00074 00075 00076 const mitk::ContourSet* mitk::ContourSetToPointSetFilter::GetInput(void) 00077 { 00078 if (this->GetNumberOfInputs() < 1) 00079 { 00080 return 0; 00081 } 00082 00083 return static_cast<const mitk::ContourSet * > 00084 ( this->BaseProcess::GetInput(0) ); 00085 } 00086 00087 void mitk::ContourSetToPointSetFilter::SetInput(const mitk::ContourSet *input) 00088 { 00089 // Process object is not const-correct so the const_cast is required here 00090 this->BaseProcess::SetNthInput(0, 00091 const_cast< mitk::ContourSet * >( input ) ); 00092 }