diff --git a/Modules/IGT/IGTFilters/mitkNavigationDataToPointSetFilter.cpp b/Modules/IGT/IGTFilters/mitkNavigationDataToPointSetFilter.cpp index aa88ac15bf..3b8b23e1b4 100644 --- a/Modules/IGT/IGTFilters/mitkNavigationDataToPointSetFilter.cpp +++ b/Modules/IGT/IGTFilters/mitkNavigationDataToPointSetFilter.cpp @@ -1,247 +1,247 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2007-01-08 17:30:05 +0100 (Mo, 08 Jan 2007) $ Version: $Revision: 8970 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/ for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkNavigationDataToPointSetFilter.h" #include #include #include #include mitk::NavigationDataToPointSetFilter::NavigationDataToPointSetFilter() { this->SetNumberOfRequiredInputs(1); m_OperationMode = Mode3D; m_CurrentTimeStep = 0; m_RingBufferSize = 50; //the default ring buffer size + m_NumberForMean = 100; } mitk::NavigationDataToPointSetFilter::~NavigationDataToPointSetFilter() { } void mitk::NavigationDataToPointSetFilter::GenerateData() { switch (m_OperationMode) { case Mode3D: GenerateDataMode3D(); break; case Mode3DMean: GenerateDataMode3DMean(); break; case Mode4D: GenerateDataMode4D(); break; default: break; } } void mitk::NavigationDataToPointSetFilter::SetInput(const NavigationData* nd) { // Process object is not const-correct so the const_cast is required here this->ProcessObject::SetNthInput(0, const_cast(nd)); this->CreateOutputsForAllInputs(); } void mitk::NavigationDataToPointSetFilter::SetInput(unsigned int idx, const NavigationData* nd) { // Process object is not const-correct so the const_cast is required here this->ProcessObject::SetNthInput(idx, const_cast(nd)); this->CreateOutputsForAllInputs(); } const mitk::NavigationData* mitk::NavigationDataToPointSetFilter::GetInput( void ) { if (this->GetNumberOfInputs() < 1) return NULL; return static_cast(this->ProcessObject::GetInput(0)); } const mitk::NavigationData* mitk::NavigationDataToPointSetFilter::GetInput( unsigned int idx ) { if (this->GetNumberOfInputs() < 1) return NULL; return static_cast(this->ProcessObject::GetInput(idx)); } void mitk::NavigationDataToPointSetFilter::CreateOutputsForAllInputs() { switch (m_OperationMode) { case Mode3D: this->SetNumberOfOutputs(this->GetNumberOfInputs()); // create one pointset output for each navigation data input break; case Mode3DMean: this->SetNumberOfOutputs(this->GetNumberOfInputs()); // create one pointset output for each navigation data input break; case Mode4D: this->SetNumberOfOutputs(1); // create just one output pointset that will contain all input navigation data objects break; default: break; } for (unsigned int idx = 0; idx < this->GetNumberOfOutputs(); ++idx) if (this->GetOutput(idx) == NULL) { DataObjectPointer newOutput = this->MakeOutput(idx); this->SetNthOutput(idx, newOutput); } this->Modified(); } void mitk::NavigationDataToPointSetFilter::GenerateDataMode3D() { for (unsigned int i = 0; i < this->GetNumberOfOutputs() ; ++i) // for each output PointSet { mitk::PointSet* output = this->GetOutput(i); assert(output); const mitk::NavigationData* input = this->GetInput(i); assert(input); if (input->IsDataValid() == false) // don't add point if input is invalid continue; mitk::PointSet::PointType pos = input->GetPosition(); // NavigationData::PositionType must be compatible with PointSet::PointType! output->InsertPoint(output->GetSize(), pos); // add point with current position of input NavigationData to the output PointSet // \TODO: regard ringbuffersize } } /** * @brief read n times all connected inputs and sum them into outputs. Finish with dividing each output by n. **/ void mitk::NavigationDataToPointSetFilter::GenerateDataMode3DMean() { //make it editable through a Set method if needed - const unsigned int numberforMean = 5; //check for outputs and inputs for (unsigned int i = 0; i < this->GetNumberOfOutputs() ; ++i) // for each output PointSet; change through pointsets to collect all navigation data in order { assert(this->GetOutput(i)); assert(this->GetInput(i)); } //vector of counters for each output - std::vector counterVec(this->GetNumberOfOutputs()); + std::vector counterVec(this->GetNumberOfOutputs(),0); + + //vector of old timesteps for each output + std::vector vectorOldTime(this->GetNumberOfOutputs()); //use first Output to get the size of the pointsets. All output pointssets have to have the same size! mitk::PointSet::PointIdentifier newPointId = this->GetOutput(0)->GetSize(); - //for (unsigned int counter = 0; counter < numberforMean; counter++) - //{ - MITK_INFO<GetNumberOfOutputs(); - for (unsigned int i = 0; i < this->GetNumberOfOutputs() ; ++i) // for each output PointSet; change through pointsets to collect all navigation data in order + bool numberForMean_is_reached = false; + while (!numberForMean_is_reached) { - counterVec[i] = 0; - while (counterVec[i]GetNumberOfOutputs() ; ++i) // for each output PointSet; change through pointsets to collect all navigation data in order { - //MITK_INFO<<"counterVecBegin: "<GetOutput(i); - const mitk::NavigationData* input = this->GetInput(i); - mitk::NavigationData::TimeStampType oldTime = input->GetTimeStamp(); - if (input->IsDataValid() == false) // don't add point if input is invalid - continue;//do not store - mitk::PointSet::PointType pos; - if (counterVec[i] == 0) //first Element must be inserted - { - //no need to call an update - pos = input->GetPosition(); // NavigationData::PositionType must be compatible with PointSet::PointType! - output->InsertPoint(newPointId, pos); // add point with current position of input NavigationData to the output PointSet - counterVec[i]++; - } - else - { - //manually call an update to track new positions - this->ProcessObject::GetInput(i)->Update(); - input = this->GetInput(i); - mitk::NavigationData::TimeStampType newTime = input->GetTimeStamp(); - if (oldTime!=newTime) + mitk::PointSet* output = this->GetOutput(i); + const mitk::NavigationData* input = this->GetInput(i); + if (input->IsDataValid() == false) // don't add point if input is invalid + continue;//do not store + mitk::PointSet::PointType pos; + if (counterVec[i] == 0) //first Element must be inserted { - MITK_INFO<<"old time: "<GetPosition(); // NavigationData::PositionType must be compatible with PointSet::PointType! - MITK_INFO<GetTimeStamp(); - //calculate the summ of the old position and the current coordinate - mitk::Vector3D vec; - vec.SetVnlVector(pos.GetVnlVector()); - mitk::PointSet::PointType oPoint = output->GetPoint(newPointId); - oPoint += vec;//summ up - output->SetPoint(newPointId, oPoint); - - //store in counterVec to know how many have been added (and not skipped because of invalid data) + //no need to call an update + pos = input->GetPosition(); // NavigationData::PositionType must be compatible with PointSet::PointType! + output->InsertPoint(newPointId, pos); // add point with current position of input NavigationData to the output PointSet counterVec[i]++; - oldTime = newTime; } - } - // \TODO: regard ringbuffersize + else + { + //manually call an update to track new positions + this->ProcessObject::GetInput(i)->Update(); + input = this->GetInput(i); + mitk::NavigationData::TimeStampType newTime = input->GetTimeStamp(); + if (vectorOldTime[i]GetPosition(); // NavigationData::PositionType must be compatible with PointSet::PointType! + + //calculate the summ of the old position and the current coordinate + mitk::Vector3D vec; + vec.SetVnlVector(pos.GetVnlVector()); + mitk::PointSet::PointType oPoint = output->GetPoint(newPointId); + oPoint += vec;//summ up + output->SetPoint(newPointId, oPoint); + + //store in counterVec to know how many have been added (and not skipped because of invalid data) + counterVec[i]++; + vectorOldTime[i] = newTime; + } + } + // \TODO: regard ringbuffersize + } + numberForMean_is_reached = true; + for (unsigned int i = 0; i < this->GetNumberOfOutputs() ; ++i) + { + if (counterVec[i]GetNumberOfOutputs() ; ++i) // for each output PointSet; change through pointsets to collect all navigation data in order { mitk::PointSet* output = this->GetOutput(i); mitk::PointSet::PointType oPoint = output->GetPoint(newPointId); for (unsigned int index = 0; index < oPoint.Size(); index++) oPoint[index] = oPoint[index] / counterVec[i]; output->SetPoint(newPointId, oPoint); - MBI_INFO << "For output # " << i << " " << counterVec[i] << " tracked positions used for averaging"; + MBI_INFO << "For output # " << i << ", " << counterVec[i] << " tracked positions used for averaging"; } - - } void mitk::NavigationDataToPointSetFilter::GenerateDataMode4D() { mitk::PointSet* output = GetOutput(); assert(output); for (unsigned int index = 0; index < this->GetNumberOfInputs(); index++) { const mitk::NavigationData* nd = GetInput(index); assert(nd); mitk::NavigationData::PositionType point = nd->GetPosition(); //get the position output->SetPoint( index, point, m_CurrentTimeStep); //store it in the pointset always at the current time step } if (m_CurrentTimeStep == m_RingBufferSize - 1) // update ring buffer index m_CurrentTimeStep = 0; else m_CurrentTimeStep++; } void mitk::NavigationDataToPointSetFilter::SetOperationMode( OperationMode mode ) { m_OperationMode = mode; //Initialize 4D Mode if (m_OperationMode == Mode4D) m_CurrentTimeStep = 0; this->Modified(); this->CreateOutputsForAllInputs(); } diff --git a/Modules/IGT/IGTFilters/mitkNavigationDataToPointSetFilter.h b/Modules/IGT/IGTFilters/mitkNavigationDataToPointSetFilter.h index 481b86564e..7949cb291c 100644 --- a/Modules/IGT/IGTFilters/mitkNavigationDataToPointSetFilter.h +++ b/Modules/IGT/IGTFilters/mitkNavigationDataToPointSetFilter.h @@ -1,144 +1,157 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2008-08-25 18:10:57 +0200 (Mo, 25 Aug 2008) $ Version: $Revision: 15062 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/ for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef _MITKNAVIGATIONDATATOPOINTSETFILTER_H__ #define _MITKNAVIGATIONDATATOPOINTSETFILTER_H__ #include "mitkCommon.h" #include "mitkPointSet.h" #include "mitkPointSetSource.h" #include "mitkNavigationData.h" namespace mitk { /**Documentation * * \brief This filter creates mitk::PointSet objects from mitk::NavigaitionData objects * * This filter has two modes that can be set with SetOperationMode(). * - Mode3D: every input NavigationData is processed into one output pointset. For each call to Update() a point with the ND position will be added to the PointSet * - Mode4D: one output pointset is generated that contains one point for each input NavigationData. Each call to Update() adds a new timestep to the PointSet that contains new positions for the points. * * \ingroup IGT * */ class MitkIGT_EXPORT NavigationDataToPointSetFilter : public PointSetSource { public: mitkClassMacro(NavigationDataToPointSetFilter, PointSetSource); itkNewMacro(Self); /**Documentation * \brief There are two different operation modes. * * - Mode3D: every input NavigationData is processed into one output pointset that contains a point with the ND position for each Update() * - Mode3DMean: a defined number of input NavigationData is used to generate a mean position and processed into one output pointset that contains a point with the ND position for each Update() * - Mode4D: one output pointset is generated that contains one point for each input NavigationData. Each call to Update() adds a new timestep to the PointSet that contains new positions for the points. * The RingBufferSize limits the number of timesteps in the 4D mode. It currently does _not_ limit the number of points in the 3D mode. */ enum OperationMode { Mode3D, Mode3DMean, Mode4D }; /**Documentation * \brief Sets the size for the ring buffer. * * The size determines the maximum number of timesteps in 4D mode and the number of points in 3D mode of the output PointSet */ itkSetMacro(RingBufferSize, unsigned int) + + /** + * \brief Sets the number of Navigation Data, which should be averaged. + */ + itkSetMacro(NumberForMean, unsigned int) + + /** + * \brief Gets the number of Navigation Data, which should be averaged. + */ + itkGetMacro(NumberForMean, unsigned int); + + /** * \brief filter execute method */ virtual void GenerateData(); /** * \brief Sets one input NavigationData */ virtual void SetInput(const mitk::NavigationData *NavigationData); /** * \brief Sets the input NavigationData at a specific index */ virtual void SetInput(unsigned int idx, const NavigationData* nd); /** * \brief Returns the input of this filter */ const mitk::NavigationData* GetInput(); /** * \brief Returns the input number idx of this filter */ const mitk::NavigationData* GetInput(unsigned int idx); /** * \brief Sets the mode of this filter. * * See OperationMode for the behavior in the different modes * \warn A call to this method will change the number of outputs of the filter. * After calling this method, all previously acquired pointers to outputs are invalid * Always set the operation mode first, then get the outputs with GetOutput() */ virtual void SetOperationMode(OperationMode mode); /** * \brief returns the mode of this filter. * * See OperationMode for the behavior in the different modes */ itkGetConstMacro(OperationMode, OperationMode); void GenerateOutputInformation() {}; ///< empty implementation to prevent calling of the superclass method that would try to copy information from the input NavigationData to the output PointSet, which makes no sense! protected: NavigationDataToPointSetFilter(); virtual ~NavigationDataToPointSetFilter(); /** * \brief Generates the output for Mode3D * */ virtual void GenerateDataMode3D(); /** * \brief Generates the output for Mode3DMean * */ virtual void GenerateDataMode3DMean(); /** * \brief Generates the output for Mode4D */ virtual void GenerateDataMode4D(); /** * \brief create output objects according to OperationMode for all inputs */ virtual void CreateOutputsForAllInputs(); OperationMode m_OperationMode; ///< Stores the mode. See enum OperationMode unsigned int m_RingBufferSize; ///< Stores the ringbuffer size unsigned int m_CurrentTimeStep; ///< Indicates the current timestamp + unsigned int m_NumberForMean; ///< Number of Navigation Data, which should be averaged }; } // namespace mitk #endif // _MITKNAVIGATIONDATATOPOINTSETFILTER_H__ diff --git a/Modules/IGT/Testing/mitkNavigationDataToPointSetFilterTest.cpp b/Modules/IGT/Testing/mitkNavigationDataToPointSetFilterTest.cpp index b686331e47..5f31ab4956 100644 --- a/Modules/IGT/Testing/mitkNavigationDataToPointSetFilterTest.cpp +++ b/Modules/IGT/Testing/mitkNavigationDataToPointSetFilterTest.cpp @@ -1,396 +1,252 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2008-02-25 17:27:17 +0100 (Mo, 25 Feb 2008) $ Version: $Revision: 7837 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkNavigationDataToPointSetFilter.h" #include "mitkNavigationDataPlayer.h" #include "mitkTimeStamp.h" #include "mitkStandardFileLocations.h" #include "mitkTestingMacros.h" #include #include /** * Simple example for a test for the (non-existent) class "NavigationDataToPointSetFilter". * * argc and argv are the command line parameters which were passed to * the ADD_TEST command in the CMakeLists.txt file. For the automatic * tests, argv is either empty for the simple tests or contains the filename * of a test image for the image tests (see CMakeLists.txt). */ class mitkNavigationDataToPointSetFilterTestClass { public: static void TestMode3D(mitk::NavigationDataToPointSetFilter::Pointer myNavigationDataToPointSetFilter) { myNavigationDataToPointSetFilter->SetOperationMode(mitk::NavigationDataToPointSetFilter::Mode3D); //Build up test data mitk::NavigationData::Pointer nd0 = mitk::NavigationData::New(); mitk::NavigationData::Pointer nd1 = mitk::NavigationData::New(); mitk::NavigationData::Pointer nd2 = mitk::NavigationData::New(); mitk::NavigationData::Pointer nd3 = mitk::NavigationData::New(); mitk::NavigationData::PositionType point0; point0[0] = 1.0; point0[1] = 2.0; point0[2] = 3.0; nd0->SetPosition(point0); nd0->SetDataValid(true); mitk::NavigationData::PositionType point1; point1[0] = 4.0; point1[1] = 5.0; point1[2] = 6.0; nd1->SetPosition(point1); nd1->SetDataValid(true); mitk::NavigationData::PositionType point2; point2[0] = 7.0; point2[1] = 8.0; point2[2] = 9.0; nd2->SetPosition(point2); nd2->SetDataValid(true); mitk::NavigationData::PositionType point3; point3[0] = 10.0; point3[1] = 11.0; point3[2] = 12.0; nd3->SetPosition(point3); nd3->SetDataValid(true); myNavigationDataToPointSetFilter->SetInput(0, nd0); myNavigationDataToPointSetFilter->SetInput(1, nd1); myNavigationDataToPointSetFilter->SetInput(2, nd2); myNavigationDataToPointSetFilter->SetInput(3, nd3); //Process mitk::PointSet::Pointer pointSet0 = myNavigationDataToPointSetFilter->GetOutput(0); mitk::PointSet::Pointer pointSet1 = myNavigationDataToPointSetFilter->GetOutput(1); mitk::PointSet::Pointer pointSet2 = myNavigationDataToPointSetFilter->GetOutput(2); mitk::PointSet::Pointer pointSet3 = myNavigationDataToPointSetFilter->GetOutput(3); pointSet0->Update(); MITK_TEST_OUTPUT(<< "Testing the conversion of navigation data object to PointSets in Mode 3D:"); MITK_TEST_CONDITION(mitk::Equal(pointSet0->GetPoint(0), point0), "Pointset 0 correct?"); MITK_TEST_CONDITION(mitk::Equal(pointSet1->GetPoint(0), point1), "Pointset 1 correct?"); MITK_TEST_CONDITION(mitk::Equal(pointSet2->GetPoint(0), point2), "Pointset 2 correct?"); MITK_TEST_CONDITION(mitk::Equal(pointSet3->GetPoint(0), point3), "Pointset 3 correct?"); //pointSet0->GetPoint(0)[0] == 1.0 && pointSet0->GetPoint(0)[1] == 2.0 && pointSet0->GetPoint(0)[2] == 3.0 && // pointSet1->GetPoint(0)[0] == 4.0 && pointSet1->GetPoint(0)[1] == 5.0 && pointSet1->GetPoint(0)[2] == 6.0 && // pointSet2->GetPoint(0)[0] == 7.0 && pointSet2->GetPoint(0)[1] == 8.0 && pointSet2->GetPoint(0)[2] == 9.0 && // pointSet3->GetPoint(0)[0] == 10.0 && pointSet3->GetPoint(0)[1] == 11.0 && pointSet3->GetPoint(0)[2] == 12.0 //, "Testing the conversion of navigation data object to PointSets in Mode 3D" ); } static void TestMode4D(mitk::NavigationDataToPointSetFilter::Pointer myNavigationDataToPointSetFilter) { myNavigationDataToPointSetFilter->SetOperationMode(mitk::NavigationDataToPointSetFilter::Mode4D); myNavigationDataToPointSetFilter->SetRingBufferSize(2); //Build up test data mitk::NavigationData::Pointer nd = mitk::NavigationData::New(); mitk::NavigationData::Pointer nd2 = mitk::NavigationData::New(); mitk::NavigationData::Pointer nd3 = mitk::NavigationData::New(); mitk::NavigationData::Pointer nd4 = mitk::NavigationData::New(); mitk::NavigationData::PositionType point; point[0] = 1.0; point[1] = 2.0; point[2] = 3.0; nd->SetPosition(point); point[0] = 4.0; point[1] = 5.0; point[2] = 6.0; nd2->SetPosition(point); point[0] = 7.0; point[1] = 8.0; point[2] = 9.0; nd3->SetPosition(point); point[0] = 10.0; point[1] = 11.0; point[2] = 12.0; nd4->SetPosition(point); myNavigationDataToPointSetFilter->SetInput(0, nd); myNavigationDataToPointSetFilter->SetInput(1, nd2); mitk::PointSet::Pointer pointSet = myNavigationDataToPointSetFilter->GetOutput(); pointSet->Update(); MITK_TEST_CONDITION( pointSet->GetPoint(0,0)[0] == 1.0 && pointSet->GetPoint(0,0)[1] == 2.0 && pointSet->GetPoint(0,0)[2] == 3.0 && pointSet->GetPoint(1,0)[0] == 4.0 && pointSet->GetPoint(1,0)[1] == 5.0 && pointSet->GetPoint(1,0)[2] == 6.0 , "Testing the conversion of navigation data object to one point set in Mode 4D in first timestep" ); myNavigationDataToPointSetFilter->SetInput(0, nd3); myNavigationDataToPointSetFilter->SetInput(1, nd4); myNavigationDataToPointSetFilter->Update(); pointSet = myNavigationDataToPointSetFilter->GetOutput(); MITK_TEST_CONDITION( pointSet->GetPoint(0,0)[0] == 1.0 && pointSet->GetPoint(0,0)[1] == 2.0 && pointSet->GetPoint(0,0)[2] == 3.0 && pointSet->GetPoint(1,0)[0] == 4.0 && pointSet->GetPoint(1,0)[1] == 5.0 && pointSet->GetPoint(1,0)[2] == 6.0 && pointSet->GetPoint(0,1)[0] == 7.0 && pointSet->GetPoint(0,1)[1] == 8.0 && pointSet->GetPoint(0,1)[2] == 9.0 && pointSet->GetPoint(1,1)[0] == 10.0 && pointSet->GetPoint(1,1)[1] == 11.0 && pointSet->GetPoint(1,1)[2] == 12.0 , "Testing the conversion of navigation data object to one point set in Mode 4D in second timestep" ); myNavigationDataToPointSetFilter->SetInput(0, nd3); //nd3->Modified(); //necessary because the generate data is only called when input has changed... myNavigationDataToPointSetFilter->SetInput(1, nd4); //nd4->Modified(); //myNavigationDataToPointSetFilter->Update(); pointSet = myNavigationDataToPointSetFilter->GetOutput(); pointSet->Update(); MITK_TEST_CONDITION( pointSet->GetPoint(0,0)[0] == 7.0 && pointSet->GetPoint(0,0)[1] == 8.0 && pointSet->GetPoint(0,0)[2] == 9.0 && pointSet->GetPoint(1,0)[0] == 10.0 && pointSet->GetPoint(1,0)[1] == 11.0 && pointSet->GetPoint(1,0)[2] == 12.0 && pointSet->GetPoint(0,1)[0] == 7.0 && pointSet->GetPoint(0,1)[1] == 8.0 && pointSet->GetPoint(0,1)[2] == 9.0 && pointSet->GetPoint(1,1)[0] == 10.0 && pointSet->GetPoint(1,1)[1] == 11.0 && pointSet->GetPoint(1,1)[2] == 12.0 , "Testing the correct ring buffer behavior" ); } static void TestMode3DMean(mitk::NavigationDataToPointSetFilter::Pointer myNavigationDataToPointSetFilter) { myNavigationDataToPointSetFilter->SetOperationMode(mitk::NavigationDataToPointSetFilter::Mode3DMean); + int numberForMean = 5; + myNavigationDataToPointSetFilter->SetNumberForMean(numberForMean); + MITK_TEST_CONDITION(mitk::Equal(myNavigationDataToPointSetFilter->GetNumberForMean(), numberForMean), "Testing get/set for numberForMean"); mitk::NavigationDataPlayer::Pointer player = mitk::NavigationDataPlayer::New(); - std::string file = mitk::StandardFileLocations::GetInstance()->FindFile("NavigationDataTestData.xml", "Modules/IGT/Testing/Data"); + std::string file = mitk::StandardFileLocations::GetInstance()->FindFile("NavigationDataTestData_2Tools.xml", "Modules/IGT/Testing/Data"); player->SetFileName( file ); - - std::vector times;//, refTimes; - - mitk::TimeStamp::Pointer timer = mitk::TimeStamp::GetInstance(); - timer->Initialize(); - std::vector points; - - itk::Object::Pointer obj = itk::Object::New(); - - mitk::Point3D pnt; - pnt[0] = 1; - pnt[1] = 0; - pnt[2] = 3; - - mitk::Point3D oldPos; - oldPos[0] = 1; - oldPos[1] = 0; - oldPos[2] = 3; - - timer->Start( obj ); - player->StartPlaying(); - //player->Update(); - //mitk::NavigationData::Pointer nd78 = player->GetOutput(); - - myNavigationDataToPointSetFilter->SetInput(player->GetOutput()); - mitk::PointSet::Pointer pointSet10 = myNavigationDataToPointSetFilter->GetOutput(); - - pointSet10->Update(); - - MITK_INFO<GetPoint(0); - - ////while( times.size()<5 ) - ////{ - //// //myNavigationDataToPointSetFilter->Update(); - //// pointSet10->Update(); - //// //myNavigationDataToPointSetFilter->Update(); - //// pnt = player->GetOutput()->GetPosition(); - //// if ( pnt != oldPos ) - //// { - //// times.push_back( timer->GetElapsed(obj) ); - //// points.push_back(oldPos); - //// oldPos = pnt; - //// } - ////} - player->StopPlaying(); - - - //////////////player->SetStream( mitk::NavigationDataPlayer::NormalFile ); - //////////////player->StartPlaying(); - //////////////player->Update(); - //////////////mitk::NavigationData::Pointer nd22 = player->GetOutput(); - //////////////player->Update(); - //////////////mitk::NavigationData::Pointer nd33 = player->GetOutput(); - - //////////////player->StopPlaying(); - - - - //MITK_TEST_CONDITION_REQUIRED( nd->GetPosition() == pnt, "Testing position of replayed NavigaionData" ); - - - - //Build up test data - mitk::NavigationData::Pointer nd0 = mitk::NavigationData::New(); - mitk::NavigationData::Pointer nd1 = mitk::NavigationData::New(); - mitk::NavigationData::Pointer nd2 = mitk::NavigationData::New(); - mitk::NavigationData::Pointer nd3 = mitk::NavigationData::New(); - - mitk::NavigationData::PositionType point0; - point0[0] = 1.0; - point0[1] = 2.0; - point0[2] = 3.0; - nd0->SetPosition(point0); - nd0->SetDataValid(true); - - mitk::NavigationData::PositionType point1; - point1[0] = 4.0; - point1[1] = 5.0; - point1[2] = 6.0; - nd1->SetPosition(point1); - nd1->SetDataValid(true); - - mitk::NavigationData::PositionType point2; - point2[0] = 7.0; - point2[1] = 8.0; - point2[2] = 9.0; - nd2->SetPosition(point2); - nd2->SetDataValid(true); - - mitk::NavigationData::PositionType point3; - point3[0] = 10.0; - point3[1] = 11.0; - point3[2] = 12.0; - nd3->SetPosition(point3); - nd3->SetDataValid(true); - - myNavigationDataToPointSetFilter->SetInput(0, nd0); - myNavigationDataToPointSetFilter->SetInput(0, nd3); + for (int i = 0; i< player->GetNumberOfOutputs(); i++) + { + myNavigationDataToPointSetFilter->SetInput(i, player->GetOutput(i)); + } - myNavigationDataToPointSetFilter->SetInput(1, nd1); - myNavigationDataToPointSetFilter->SetInput(2, nd2); - myNavigationDataToPointSetFilter->SetInput(3, nd3); - - //myNavigationDataToPointSetFilter->SetInput(0, nd1); - //myNavigationDataToPointSetFilter->SetInput(1, nd0); - - //Process mitk::PointSet::Pointer pointSet0 = myNavigationDataToPointSetFilter->GetOutput(0); mitk::PointSet::Pointer pointSet1 = myNavigationDataToPointSetFilter->GetOutput(1); - pointSet0->Update(); - - std::cout << "pointSet0 " << pointSet0->GetPoint(0,0)[0] << std::endl; - std::cout << "pointSet0 " << pointSet0->GetPoint(0,0)[1] << std::endl; - std::cout << "pointSet0 " << pointSet0->GetPoint(0,0)[2] << std::endl; - std::cout << "pointSet0 " << pointSet0->GetPoint(1,0)[0] << std::endl; - std::cout << "pointSet0 " << pointSet0->GetPoint(0,1)[0] << std::endl; - - std::cout << "pointSet1 " << pointSet1->GetPoint(0,0)[0] << std::endl; - std::cout << "pointSet1 " << pointSet1->GetPoint(0,0)[1] << std::endl; - std::cout << "pointSet1 " << pointSet1->GetPoint(0,0)[2] << std::endl; - std::cout << "pointSet1 " << pointSet1->GetPoint(1,0)[0] << std::endl; - std::cout << "pointSet1 " << pointSet1->GetPoint(0,1)[0] << std::endl; - - - myNavigationDataToPointSetFilter->SetInput(0, nd1); - myNavigationDataToPointSetFilter->SetInput(1, nd0); - myNavigationDataToPointSetFilter->SetInput(2, nd3); - myNavigationDataToPointSetFilter->SetInput(3, nd2); - - - //Process - mitk::PointSet::Pointer pointSet2 = myNavigationDataToPointSetFilter->GetOutput(0); - mitk::PointSet::Pointer pointSet3 = myNavigationDataToPointSetFilter->GetOutput(1); - - mitk::PointSet::Pointer pointSet4 = myNavigationDataToPointSetFilter->GetOutput(2); - mitk::PointSet::Pointer pointSet5 = myNavigationDataToPointSetFilter->GetOutput(3); - - pointSet0->Update(); - - std::cout << "pointSet2 " << pointSet2->GetPoint(0,0)[0] << std::endl; - std::cout << "pointSet2 " << pointSet2->GetPoint(0,0)[1] << std::endl; - std::cout << "pointSet2 " << pointSet2->GetPoint(0,0)[1] << std::endl; - std::cout << "pointSet2 " << pointSet2->GetPoint(1,0)[0] << std::endl; - std::cout << "pointSet2 " << pointSet2->GetPoint(0,1)[0] << std::endl; - - std::cout << "pointSet3 " << pointSet3->GetPoint(0,0)[0] << std::endl; - std::cout << "pointSet3 " << pointSet3->GetPoint(0,0)[1] << std::endl; - std::cout << "pointSet3 " << pointSet3->GetPoint(0,0)[2] << std::endl; - std::cout << "pointSet3 " << pointSet3->GetPoint(1,0)[0] << std::endl; - std::cout << "pointSet3 " << pointSet3->GetPoint(0,1)[0] << std::endl; + myNavigationDataToPointSetFilter->Update(); + player->StopPlaying(); - MITK_TEST_OUTPUT(<< "Testing the conversion of navigation data object to PointSets in Mode 3D:"); - MITK_TEST_CONDITION(mitk::Equal(pointSet0->GetPoint(0), point0), "Pointset 0 correct?"); - MITK_TEST_CONDITION(mitk::Equal(pointSet1->GetPoint(0), point1), "Pointset 1 correct?"); - MITK_TEST_CONDITION(mitk::Equal(pointSet2->GetPoint(0), point2), "Pointset 2 correct?"); - MITK_TEST_CONDITION(mitk::Equal(pointSet3->GetPoint(0), point3), "Pointset 3 correct?"); + MITK_TEST_CONDITION(pointSet0->GetPoint(0)[0]==3.0 && pointSet0->GetPoint(0)[1]==2.0 && pointSet0->GetPoint(0)[2]==5.0, + "Testing the average of first input"); - //pointSet0->GetPoint(0)[0] == 1.0 && pointSet0->GetPoint(0)[1] == 2.0 && pointSet0->GetPoint(0)[2] == 3.0 && - // pointSet1->GetPoint(0)[0] == 4.0 && pointSet1->GetPoint(0)[1] == 5.0 && pointSet1->GetPoint(0)[2] == 6.0 && - // pointSet2->GetPoint(0)[0] == 7.0 && pointSet2->GetPoint(0)[1] == 8.0 && pointSet2->GetPoint(0)[2] == 9.0 && - // pointSet3->GetPoint(0)[0] == 10.0 && pointSet3->GetPoint(0)[1] == 11.0 && pointSet3->GetPoint(0)[2] == 12.0 - //, "Testing the conversion of navigation data object to PointSets in Mode 3D" ); + MITK_TEST_CONDITION(pointSet1->GetPoint(0)[0]==30.0 && pointSet1->GetPoint(0)[1]==20.0 && pointSet1->GetPoint(0)[2]==50.0, + "Testing the average of second input"); } }; int mitkNavigationDataToPointSetFilterTest(int /* argc */, char* /*argv*/[]) { // always start with this! MITK_TEST_BEGIN("NavigationDataToPointSetFilter"); // let's create an object of our class mitk::NavigationDataToPointSetFilter::Pointer myNavigationDataToPointSetFilter = mitk::NavigationDataToPointSetFilter::New(); // first test: did this work? // using MITK_TEST_CONDITION_REQUIRED makes the test stop after failure, since // it makes no sense to continue without an object. MITK_TEST_CONDITION_REQUIRED(myNavigationDataToPointSetFilter.IsNotNull(),"Testing instantiation"); // write your own tests here and use the macros from mitkTestingMacros.h !!! // do not write to std::cout and do not return from this function yourself! mitk::NavigationData::Pointer nd_in = mitk::NavigationData::New(); const mitk::NavigationData* nd_out = mitk::NavigationData::New(); mitk::NavigationData::PositionType point; point[0] = 1.0; point[1] = 2.0; point[2] = 3.0; nd_in->SetPosition(point); myNavigationDataToPointSetFilter->SetInput(nd_in); nd_out = myNavigationDataToPointSetFilter->GetInput(); MITK_TEST_CONDITION( nd_out->GetPosition() == nd_in->GetPosition(), "Testing get/set input" ); myNavigationDataToPointSetFilter = mitk::NavigationDataToPointSetFilter::New(); mitkNavigationDataToPointSetFilterTestClass::TestMode3D(myNavigationDataToPointSetFilter); myNavigationDataToPointSetFilter = mitk::NavigationDataToPointSetFilter::New(); mitkNavigationDataToPointSetFilterTestClass::TestMode4D(myNavigationDataToPointSetFilter); myNavigationDataToPointSetFilter = mitk::NavigationDataToPointSetFilter::New(); mitkNavigationDataToPointSetFilterTestClass::TestMode3DMean(myNavigationDataToPointSetFilter); // always end with this! MITK_TEST_END(); }