diff --git a/Modules/Core/include/mitkPointSet.h b/Modules/Core/include/mitkPointSet.h index 99383bfea8..4a55101604 100755 --- a/Modules/Core/include/mitkPointSet.h +++ b/Modules/Core/include/mitkPointSet.h @@ -1,352 +1,348 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #ifndef MITKPointSet_H_HEADER_INCLUDED #define MITKPointSet_H_HEADER_INCLUDED #include "mitkBaseData.h" #include <itkDefaultDynamicMeshTraits.h> #include <itkMesh.h> namespace mitk { /** - * \brief Data structure which stores a set of points. Superclass of - * mitk::Mesh. + * \brief Data structure which stores a set of points. * * 3D points are grouped within a point set; for time resolved usage, one point * set is created and maintained per time step. A point entry consists of the * point coordinates and point data. * * The point data includes a point ID (unique identifier to address this point * within the point set), the selection state of the point and the type of * the point. * * For further information about different point types see * mitk::PointSpecificationType in mitkVector.h. * * Inserting a point is accompanied by an event, containing an index. The new * point is inserted into the list at the specified position. At the same time * an internal ID is generated and stored for the point. Points at specific time * steps are accessed by specifying the time step number (which defaults to 0). * * The points of itk::PointSet stores the points in a pointContainer * (MapContainer). The points are best accessed by using a ConstIterator (as * defined in MapContainer); avoid access via index. * - * The class internally uses an itk::Mesh for each time step, because - * mitk::Mesh is derived from mitk::PointSet and needs the itk::Mesh structure - * which is also derived from itk::PointSet. Thus several typedefs which seem - * to be in wrong place, are declared here (for example SelectedLinesType). + * The class internally uses an itk::Mesh for each time step. * * \section mitkPointSetDisplayOptions * * The default mappers for this data structure are mitk::PointSetGLMapper2D and * mitk::PointSetVtkMapper3D. See these classes for display options which can * can be set via properties. * * \section Events * * PointSet issues the following events, for which observers can register * (the below events are grouped into a class hierarchy as indicated by * identation level; e.g. PointSetSizeChangeEvent comprises PointSetAddEvent * and PointSetRemoveEvent): * * <tt> * PointSetEvent <i>subsumes all PointSet events</i> * PointSetMoveEvent <i>issued when a point of the PointSet is moved</i> * PointSetSizeChangeEvent <i>subsumes add and remove events</i> * PointSetAddEvent <i>issued when a point is added to the PointSet</i> * PointSetRemoveEvent <i>issued when a point is removed from the PointSet</i> * </tt> * \ingroup PSIO * \ingroup Data */ class MITKCORE_EXPORT PointSet : public BaseData { public: mitkClassMacro(PointSet, BaseData); itkFactorylessNewMacro(Self); itkCloneMacro(Self); typedef mitk::ScalarType CoordinateType; typedef mitk::ScalarType InterpolationWeightType; static const unsigned int PointDimension = 3; static const unsigned int MaxTopologicalDimension = 3; /** * \brief struct for data of a point */ struct MITKCORE_EXPORT PointDataType { unsigned int id; // to give the point a special ID bool selected; // information about if the point is selected mitk::PointSpecificationType pointSpec; // specifies the type of the point bool operator==(const PointDataType &other) const; }; /** * \brief cellDataType, that stores all indexes of the lines, that are * selected e.g.: points A,B and C.Between A and B there is a line with * index 0. If vector of cellData contains 1 and 2, then the lines between * B and C and C and A is selected. */ typedef std::vector<unsigned int> SelectedLinesType; typedef SelectedLinesType::iterator SelectedLinesIter; struct CellDataType { // used to set the whole cell on selected bool selected; // indexes of selected lines. 0 is between pointId 0 and 1 SelectedLinesType selectedLines; // is the polygon already finished and closed bool closed; }; typedef itk::DefaultDynamicMeshTraits<PointDataType, PointDimension, MaxTopologicalDimension, CoordinateType, InterpolationWeightType, CellDataType> MeshTraits; typedef itk::Mesh<PointDataType, PointDimension, MeshTraits> MeshType; typedef MeshType DataType; typedef Point3D PointType; typedef DataType::PointIdentifier PointIdentifier; typedef DataType::PointsContainer PointsContainer; typedef DataType::PointsContainerIterator PointsIterator; typedef DataType::PointsContainer::ConstIterator PointsConstIterator; typedef DataType::PointDataContainer PointDataContainer; typedef DataType::PointDataContainerIterator PointDataIterator; typedef DataType::PointDataContainerIterator PointDataConstIterator; void Expand(unsigned int timeSteps) override; /** \brief executes the given Operation */ void ExecuteOperation(Operation *operation) override; /** \brief returns the current size of the point-list */ virtual int GetSize(unsigned int t = 0) const; virtual unsigned int GetPointSetSeriesSize() const; /** \brief returns the pointset */ virtual DataType::Pointer GetPointSet(int t = 0) const; PointsIterator Begin(int t = 0); PointsConstIterator Begin(int t = 0) const; PointsIterator End(int t = 0); PointsConstIterator End(int t = 0) const; /** * \brief Get an iterator to the max ID element if existent. Return End() otherwise. */ PointsIterator GetMaxId(int t = 0); /** * \brief Get the point with ID id in world coordinates * * check if the ID exists. If it doesn't exist, then return 0,0,0 */ PointType GetPoint(PointIdentifier id, int t = 0) const; /** * \brief Get the point with ID id in world coordinates * * If a point exists for the ID id, the point is returned in the parameter point * and the method returns true. If the ID does not exist, the method returns false */ bool GetPointIfExists(PointIdentifier id, PointType *point, int t = 0) const; /** * \brief Set the given point in world coordinate system into the itkPointSet. */ void SetPoint(PointIdentifier id, PointType point, int t = 0); /** * \brief Set the given point in world coordinate system with the given PointSpecificationType */ void SetPoint(PointIdentifier id, PointType point, PointSpecificationType spec, int t = 0); /** * \brief Set the given point in world coordinate system into the itkPointSet. */ void InsertPoint(PointIdentifier id, PointType point, int t = 0); /** * \brief Set the given point in world coordinate system with given PointSpecificationType */ void InsertPoint(PointIdentifier id, PointType point, PointSpecificationType spec, int t); /** * \brief Insert the given point in world coordinate system with incremented max id at time step t. */ PointIdentifier InsertPoint(PointType point, int t = 0); /** * \brief Remove point with given id at timestep t, if existent */ bool RemovePointIfExists(PointIdentifier id, int t = 0); /** * \brief Remove max id point at timestep t and return iterator to precedent point */ PointsIterator RemovePointAtEnd(int t = 0); /** * \brief Swap a point at the given position (id) with the upper point (moveUpwards=true) or with the lower point * (moveUpwards=false). * If upper or lower index does not exist false is returned, if swap was successful true. */ bool SwapPointPosition(PointIdentifier id, bool moveUpwards, int t = 0); /** * \brief searches a selected point and returns the id of that point. * If no point is found, then -1 is returned */ virtual int SearchSelectedPoint(int t = 0) const; /** \brief returns true if a point exists at this position */ virtual bool IndexExists(int position, int t = 0) const; /** \brief to get the state selected/unselected of the point on the * position */ virtual bool GetSelectInfo(int position, int t = 0) const; virtual void SetSelectInfo(int position, bool selected, int t = 0); /** \brief to get the type of the point at the position and the moment */ virtual PointSpecificationType GetSpecificationTypeInfo(int position, int t) const; /** \brief returns the number of selected points */ virtual int GetNumberOfSelected(int t = 0) const; /** * \brief searches a point in the list == point +/- distance * * \param point is in world coordinates. * \param distance is in mm. * \param t * returns -1 if no point is found * or the position in the list of the first match */ int SearchPoint(Point3D point, ScalarType distance, int t = 0) const; bool IsEmptyTimeStep(unsigned int t) const override; // virtual methods, that need to be implemented void UpdateOutputInformation() override; void SetRequestedRegionToLargestPossibleRegion() override; bool RequestedRegionIsOutsideOfTheBufferedRegion() override; bool VerifyRequestedRegion() override; void SetRequestedRegion(const itk::DataObject *data) override; // Method for subclasses virtual void OnPointSetChange(){}; protected: mitkCloneMacro(Self); PointSet(); PointSet(const PointSet &other); ~PointSet() override; void PrintSelf(std::ostream &os, itk::Indent indent) const override; ///< print content of the object to os void ClearData() override; void InitializeEmpty() override; /** \brief swaps point coordinates and point data of the points with identifiers id1 and id2 */ bool SwapPointContents(PointIdentifier id1, PointIdentifier id2, int t = 0); typedef std::vector<DataType::Pointer> PointSetSeries; PointSetSeries m_PointSetSeries; DataType::PointsContainer::Pointer m_EmptyPointsContainer; /** * @brief flag to indicate the right time to call SetBounds **/ bool m_CalculateBoundingBox; }; /** * @brief Equal A function comparing two pointsets for beeing identical. * @warning This method is deprecated and will not be available in the future. Use the \a bool mitk::Equal(const * mitk::PointSet& p1, const mitk::PointSet& p2) instead. * * @ingroup MITKTestingAPI * * The function compares the Geometry, the size and all points element-wise. * The parameter eps is a tolarence value for all methods which are internally used for comparion. * * @param rightHandSide Compare this against leftHandSide. * @param leftHandSide Compare this against rightHandSide. * @param eps Tolarence for comparison. You can use mitk::eps in most cases. * @param verbose Flag indicating if the user wants detailed console output or not. * @param checkGeometry if comparing point sets loaded from a file, the geometries might be different and must not be * compared. In all other cases, you should compare the geometries. * @return True, if all subsequent comparisons are true, false otherwise */ DEPRECATED(MITKCORE_EXPORT bool Equal(const mitk::PointSet *leftHandSide, const mitk::PointSet *rightHandSide, mitk::ScalarType eps, bool verbose, bool checkGeometry = true)); /** * @brief Equal A function comparing two pointsets for beeing identical. * * @ingroup MITKTestingAPI * * The function compares the Geometry, the size and all points element-wise. * The parameter eps is a tolarence value for all methods which are internally used for comparion. * * @param rightHandSide Compare this against leftHandSide. * @param leftHandSide Compare this against rightHandSide. * @param eps Tolarence for comparison. You can use mitk::eps in most cases. * @param verbose Flag indicating if the user wants detailed console output or not. * @param checkGeometry if comparing point sets loaded from a file, the geometries might be different and must not be * compared. In all other cases, you should compare the geometries. * @return True, if all subsequent comparisons are true, false otherwise */ MITKCORE_EXPORT bool Equal(const mitk::PointSet &leftHandSide, const mitk::PointSet &rightHandSide, mitk::ScalarType eps, bool verbose, bool checkGeometry = true); itkEventMacro(PointSetEvent, itk::AnyEvent); itkEventMacro(PointSetMoveEvent, PointSetEvent); itkEventMacro(PointSetSizeChangeEvent, PointSetEvent); itkEventMacro(PointSetAddEvent, PointSetSizeChangeEvent); itkEventMacro(PointSetRemoveEvent, PointSetSizeChangeEvent); itkEventMacro(PointSetExtendTimeRangeEvent, PointSetEvent); } // namespace mitk #endif /* MITKPointSet_H_HEADER_INCLUDED */ diff --git a/Modules/DataTypesExt/files.cmake b/Modules/DataTypesExt/files.cmake index f8569f2e63..0508c5b9f1 100644 --- a/Modules/DataTypesExt/files.cmake +++ b/Modules/DataTypesExt/files.cmake @@ -1,46 +1,45 @@ file(GLOB_RECURSE H_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/include/*") set(CPP_FILES mitkAffineBaseDataInteractor3D.cpp mitkAffineImageCropperInteractor.cpp mitkApplyDiffImageOperation.cpp mitkBoundingObject.cpp mitkBoundingObjectGroup.cpp mitkCellOperation.cpp mitkClippingPlaneInteractor3D.cpp mitkColorSequence.cpp mitkColorSequenceCycleH.cpp mitkColorSequenceRainbow.cpp mitkCompressedImageContainer.cpp mitkCone.cpp mitkCuboid.cpp mitkCylinder.cpp mitkDataStorageSelection.cpp mitkEllipsoid.cpp mitkGridRepresentationProperty.cpp mitkGridVolumeMapperProperty.cpp mitkLabeledImageLookupTable.cpp mitkLabeledImageVolumeCalculator.cpp mitkLineOperation.cpp mitkLookupTableSource.cpp - mitkMesh.cpp mitkMultiStepper.cpp mitkPlane.cpp mitkSurfaceDeformationDataInteractor3D.cpp mitkUnstructuredGrid.cpp mitkUnstructuredGridSource.cpp mitkVideoSource.cpp mitkColorConversions.cpp ) set(RESOURCE_FILES Interactions/AffineInteraction3D.xml Interactions/AffineMouseConfig.xml Interactions/AffineKeyConfig.xml Interactions/ClippingPlaneInteraction3D.xml Interactions/ClippingPlaneTranslationConfig.xml Interactions/ClippingPlaneRotationConfig.xml Interactions/ClippingPlaneDeformationConfig.xml Interactions/CropperDeformationConfig.xml ) diff --git a/Modules/DataTypesExt/include/mitkMesh.h b/Modules/DataTypesExt/include/mitkMesh.h deleted file mode 100644 index 215e71e648..0000000000 --- a/Modules/DataTypesExt/include/mitkMesh.h +++ /dev/null @@ -1,126 +0,0 @@ -/*============================================================================ - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center (DKFZ) -All rights reserved. - -Use of this source code is governed by a 3-clause BSD license that can be -found in the LICENSE file. - -============================================================================*/ - -#ifndef MITKMESH_H_HEADER_INCLUDED -#define MITKMESH_H_HEADER_INCLUDED - -#include "MitkDataTypesExtExports.h" -#include "mitkPointSet.h" - -#include <itkPolygonCell.h> -#include <vtkCellArray.h> -#include <vtkFloatArray.h> -#include <vtkPointData.h> -#include <vtkPolyData.h> - -#include <vtkPoints.h> -#include <vtkSystemIncludes.h> - -namespace mitk -{ - /** - * \brief DataStructure which stores a set of points (incl. pointdata) where - * each point can be associated to an element of a cell. - * - * A mesh contains several cells that can be of different celltypes - * (Line, Triangle, Polygone...). A cell is always closed. If a linestrip is - * to be created, then declare several cells, each containing one line. - * - * The operations take care of the coherence. If a line is added to an - * existing LineCell, then a TriangleCell is built with the old and the new - * parameter (and so on). Deletion is done the opposite way. - * - * Example for inserting a line into a TriangleCell: - * existing PIds ind the cell: 1, 2, 4; - * inserting (2, 3) so that new PIds in Cell: 1, 2, 3, 4 - * - * The cell is now of type QuadrilateralCell - * - * \ingroup Data - */ - class MITKDATATYPESEXT_EXPORT Mesh : public PointSet - { - public: - mitkClassMacro(Mesh, PointSet); - - itkFactorylessNewMacro(Self); - - itkCloneMacro(Self); - - typedef Superclass::DataType::CellType CellType; - typedef CellType::CellAutoPointer CellAutoPointer; - typedef Superclass::MeshTraits::CellTraits CellTraits; - typedef CellTraits::PointIdConstIterator PointIdConstIterator; - typedef CellTraits::PointIdIterator PointIdIterator; - typedef DataType::CellDataContainer CellDataContainer; - typedef DataType::CellDataContainerIterator CellDataIterator; - typedef Superclass::DataType::CellsContainer::Iterator CellIterator; - typedef Superclass::DataType::CellsContainer::ConstIterator ConstCellIterator; - typedef itk::PolygonCell<CellType> PolygonType; - typedef MeshType::CellType::MultiVisitor MeshMultiVisitor; - - /** \brief returns the current number of cells in the mesh */ - virtual unsigned long GetNumberOfCells(int t = 0); - - /** \brief returns the mesh */ - virtual const DataType *GetMesh(int t = 0) const; - - /** \brief returns the mesh */ - virtual DataType *GetMesh(int t = 0); - - void SetMesh(DataType *mesh, int t = 0); - - /** \brief checks if the given point is in a cell and returns that cellId. - * Basicaly it searches lines and points that are hit. - */ - virtual bool EvaluatePosition(Point3D point, unsigned long &cellId, float precision, int t = 0); - - /** \brief searches for the next new cellId and returns that id */ - unsigned long GetNewCellId(int t = 0); - - /** \brief returns the first cell that includes the given pointId */ - virtual int SearchFirstCell(unsigned long pointId, int t = 0); - - /** \brief searches for a line, that is hit by the given point. - * Then returns the lineId and the cellId - */ - virtual bool SearchLine(Point3D point, float distance, unsigned long &lineId, unsigned long &cellId, int t = 0); - - /** \brief searches a line according to the cellId and lineId and returns - * the PointIds, that assign the line; if successful, then return - * param = true; - */ - virtual bool GetPointIds(unsigned long cellId, unsigned long lineId, int &idA, int &idB, int t = 0); - - /** \brief searches a selected cell and returns the id of that cell. If no - * cell is found, then -1 is returned - */ - virtual int SearchSelectedCell(int t = 0); - - /** \brief creates a BoundingBox and computes it with the given points of - * the cell. - * - * Returns the BoundingBox != IsNull() if successful. - */ - virtual DataType::BoundingBoxPointer GetBoundingBoxFromCell(unsigned long cellId, int t = 0); - - /** \brief executes the given Operation */ - void ExecuteOperation(Operation *operation) override; - - protected: - Mesh(); - ~Mesh() override; - }; - -} // namespace mitk - -#endif /* MITKMESH_H_HEADER_INCLUDED */ diff --git a/Modules/DataTypesExt/include/mitkMeshUtil.h b/Modules/DataTypesExt/include/mitkMeshUtil.h deleted file mode 100644 index a40c69cb20..0000000000 --- a/Modules/DataTypesExt/include/mitkMeshUtil.h +++ /dev/null @@ -1,1677 +0,0 @@ -/*============================================================================ - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center (DKFZ) -All rights reserved. - -Use of this source code is governed by a 3-clause BSD license that can be -found in the LICENSE file. - -============================================================================*/ - -#ifndef MITKMESHUTIL_H_INCLUDED -#define MITKMESHUTIL_H_INCLUDED - -#if (_MSC_VER == 1200) -#error MeshUtils currently not supported for MS Visual C++ 6.0. Sorry. -#endif - -//#include <itkMesh.h> -#include <itkCellInterface.h> -#include <itkLineCell.h> -#include <itkPolygonCell.h> -#include <itkQuadrilateralCell.h> -#include <itkTriangleCell.h> -//#include <itkDefaultDynamicMeshTraits.h> -#include <itkSphereMeshSource.h> -//#include <itkTransformMeshFilter.h> -//#include <itkTranslationTransform.h> -//#include <itkMinimumMaximumImageCalculator.h> -#include <itkAutomaticTopologyMeshSource.h> -#include <itkRegularSphereMeshSource.h> -#include <vnl/vnl_cross.h> - -#include <vtkActor.h> -#include <vtkCellArray.h> -#include <vtkCellData.h> -#include <vtkFloatArray.h> -#include <vtkPointData.h> -#include <vtkPoints.h> -#include <vtkPolyData.h> -#include <vtkProperty.h> -#include <vtkUnstructuredGrid.h> - -#include <mitkBaseGeometry.h> -#include <mitkSurface.h> - -template <typename MeshType> -class NullScalarAccessor -{ -public: - static inline double GetPointScalar(typename MeshType::PointDataContainer * /*pointData*/, - typename MeshType::PointIdentifier /*idx*/, - MeshType * /*mesh*/ = nullptr, - unsigned int /*type*/ = 0) - { - return (double)0.0; - }; - - static inline double GetCellScalar(typename MeshType::CellDataContainer * /*cellData*/, - typename MeshType::CellIdentifier /*idx*/, - MeshType * /*mesh*/ = nullptr, - unsigned int /*type*/ = 0) - { - return (double)0.0; - }; -}; - -template <typename MeshType> -class MeshScalarAccessor -{ -public: - static inline double GetPointScalar(typename MeshType::PointDataContainer *pointData, - typename MeshType::PointIdentifier idx, - MeshType * /*mesh*/ = nullptr, - unsigned int /*type*/ = 0) - { - return (double)pointData->GetElement(idx); - }; - - static inline double GetCellScalar(typename MeshType::CellDataContainer *cellData, - typename MeshType::CellIdentifier idx, - MeshType * /*mesh*/ = nullptr, - unsigned int /*type*/ = 0) - { - return (double)cellData->GetElement(idx); - }; -}; - -template <typename MeshType> -class MeanCurvatureAccessor : public NullScalarAccessor<MeshType> -{ -public: - static inline double GetPointScalar(typename MeshType::PointDataContainer * /*point*/, - typename MeshType::PointIdentifier idx, - MeshType *mesh, - unsigned int /*type*/ = 0) - { - typename MeshType::PixelType dis = 0; - mesh->GetPointData(idx, &dis); - return (double)dis; - }; -}; - -template <typename MeshType> -class SimplexMeshAccessor : public NullScalarAccessor<MeshType> -{ -public: - static inline double GetPointScalar(typename MeshType::PointDataContainer * /*point*/, - typename MeshType::PointIdentifier idx, - MeshType *mesh, - unsigned int type = 0) - { - typename MeshType::GeometryMapPointer geometryData = mesh->GetGeometryData(); - - if (type == 0) - { - double val = mesh->GetMeanCurvature(idx); - mesh->SetPointData(idx, val); - return val; - } - else if (type == 1) - { - double val = geometryData->GetElement(idx)->meanTension; - mesh->SetPointData(idx, val); - return val; - } - else if (type == 2) - { - double val = geometryData->GetElement(idx)->externalForce.GetNorm(); - mesh->SetPointData(idx, val); - return val; - } - else if (type == 3) - return geometryData->GetElement(idx)->internalForce.GetNorm(); - else if (type == 4) - return geometryData->GetElement(idx)->externalForce.GetNorm() * mesh->GetDistance(idx); - else if (type == 5) - { - typename MeshType::PixelType dis = 0; - mesh->GetPointData(idx, &dis); - return (double)dis; - } - else if (type == 6) - { - return (double)((geometryData->GetElement(idx))->allowSplitting); - } - else - return (double)0; - }; -}; - -/*! -\brief The class provides mehtods for ITK - VTK mesh conversion -* -* \todo document the inner class -* \todo maybe inner class should be moved out -*/ - -template <typename MeshType, class ScalarAccessor = NullScalarAccessor<MeshType>> -class MeshUtil -{ - /*! - \brief A visitor to create VTK cells by means of a class - defining the InsertImplementation interface - - The InsertImplementation interface defines the methods - \code - void InsertLine(vtkIdType *pts); - void InsertTriangle(vtkIdType *pts); - void InsertPolygon(vtkIdType npts, vtkIdType *pts); - void InsertQuad(vtkIdType *pts); - void InsertTetra(vtkIdType *pts); - void InsertHexahedron(vtkIdType *pts); - \endcode - - This class calls the appropriate insert-method of the - InsertImplementation according to the cell type of - the visited cell \em and its actual contents: e.g., - for a polygon cell with just two points, a line will - be created by calling InsertLine. - \sa ExactSwitchByCellType - \sa SingleCellArrayInsertImplementation - \sa DistributeInsertImplementation - */ - template <class InsertImplementation> - class SwitchByCellType : public InsertImplementation - { - // typedef the itk cells we are interested in - typedef typename itk::CellInterface<typename MeshType::CellPixelType, typename MeshType::CellTraits> - CellInterfaceType; - typedef itk::LineCell<CellInterfaceType> floatLineCell; - typedef itk::TriangleCell<CellInterfaceType> floatTriangleCell; - typedef itk::PolygonCell<CellInterfaceType> floatPolygonCell; - typedef itk::QuadrilateralCell<CellInterfaceType> floatQuadrilateralCell; - typedef itk::TetrahedronCell<CellInterfaceType> floatTetrahedronCell; - typedef itk::HexahedronCell<CellInterfaceType> floatHexahedronCell; - typedef typename CellInterfaceType::PointIdConstIterator PointIdIterator; - - public: - /*! - Visit a line and create the VTK_LINE cell - */ - void Visit(unsigned long cellId, floatLineCell *t) - { - vtkIdType pts[2]; - int i = 0; - unsigned long num = t->GetNumberOfVertices(); - vtkIdType vtkCellId = -1; - if (num == 2) - { // useless because itk::LineCell always returns 2 - for (PointIdIterator it = t->PointIdsBegin(); it != t->PointIdsEnd(); it++) - pts[i++] = *it; - vtkCellId = this->InsertLine((vtkIdType *)pts); - } - - if (this->m_UseCellScalarAccessor && vtkCellId >= 0) - { - this->m_CellScalars->InsertTuple1(vtkCellId, ScalarAccessor::GetCellScalar(this->m_CellData, cellId)); - } - } - - /*! - Visit a polygon and create the VTK_POLYGON cell - */ - void Visit(unsigned long cellId, floatPolygonCell *t) - { - vtkIdType pts[4096]; - int i = 0; - unsigned long num = t->GetNumberOfVertices(); - vtkIdType vtkCellId = -1; - if (num > 4096) - { - MITK_ERROR << "Problem in mitkMeshUtil: Polygon with more than maximum number of vertices encountered." - << std::endl; - } - else if (num > 3) - { - for (PointIdIterator it = t->PointIdsBegin(); it != t->PointIdsEnd(); it++) - pts[i++] = *it; - vtkCellId = this->InsertPolygon(num, (vtkIdType *)pts); - } - else if (num == 3) - { - for (PointIdIterator it = t->PointIdsBegin(); it != t->PointIdsEnd(); it++) - pts[i++] = *it; - vtkCellId = this->InsertTriangle((vtkIdType *)pts); - } - else if (num == 2) - { - for (PointIdIterator it = t->PointIdsBegin(); it != t->PointIdsEnd(); it++) - pts[i++] = *it; - vtkCellId = this->InsertLine((vtkIdType *)pts); - } - - if (this->m_UseCellScalarAccessor && vtkCellId >= 0) - { - this->m_CellScalars->InsertTuple1(vtkCellId, ScalarAccessor::GetCellScalar(this->m_CellData, cellId)); - } - } - - /*! - Visit a triangle and create the VTK_TRIANGLE cell - */ - void Visit(unsigned long cellId, floatTriangleCell *t) - { - vtkIdType pts[3]; - int i = 0; - unsigned long num = t->GetNumberOfVertices(); - vtkIdType vtkCellId = -1; - if (num == 3) - { - for (PointIdIterator it = t->PointIdsBegin(); it != t->PointIdsEnd(); it++) - pts[i++] = *it; - vtkCellId = this->InsertTriangle((vtkIdType *)pts); - } - else if (num == 2) - { - for (PointIdIterator it = t->PointIdsBegin(); it != t->PointIdsEnd(); it++) - pts[i++] = *it; - vtkCellId = this->InsertLine((vtkIdType *)pts); - } - - if (this->m_UseCellScalarAccessor && vtkCellId >= 0) - { - this->m_CellScalars->InsertTuple1(vtkCellId, ScalarAccessor::GetCellScalar(this->m_CellData, cellId)); - } - } - - /*! - Visit a quad and create the VTK_QUAD cell - */ - void Visit(unsigned long cellId, floatQuadrilateralCell *t) - { - vtkIdType pts[4]; - int i = 0; - unsigned long num = t->GetNumberOfVertices(); - vtkIdType vtkCellId = -1; - if (num == 4) - { - for (PointIdIterator it = t->PointIdsBegin(); it != t->PointIdsEnd(); it++) - { - if (i == 2) - pts[3] = *it; - else if (i == 3) - pts[2] = *it; - else - pts[i] = *it; - i++; - // pts[i++] = *it; - } - vtkCellId = this->InsertQuad((vtkIdType *)pts); - } - else if (num == 3) - { - for (PointIdIterator it = t->PointIdsBegin(); it != t->PointIdsEnd(); it++) - pts[i++] = *it; - vtkCellId = this->InsertTriangle((vtkIdType *)pts); - } - else if (num == 2) - { - for (PointIdIterator it = t->PointIdsBegin(); it != t->PointIdsEnd(); it++) - pts[i++] = *it; - vtkCellId = this->InsertLine((vtkIdType *)pts); - } - - if (this->m_UseCellScalarAccessor && vtkCellId >= 0) - { - this->m_CellScalars->InsertTuple1(vtkCellId, ScalarAccessor::GetCellScalar(this->m_CellData, cellId)); - } - } - - /*! - Visit a tetrahedra and create the VTK_TETRA cell - */ - void Visit(unsigned long cellId, floatTetrahedronCell *t) - { - vtkIdType pts[4]; - int i = 0; - unsigned long num = t->GetNumberOfVertices(); - vtkIdType vtkCellId = -1; - if (num == 4) - { - for (PointIdIterator it = t->PointIdsBegin(); it != t->PointIdsEnd(); it++) - pts[i++] = *it; - vtkCellId = this->InsertTetra((vtkIdType *)pts); - } - else if (num == 3) - { - for (PointIdIterator it = t->PointIdsBegin(); it != t->PointIdsEnd(); it++) - pts[i++] = *it; - vtkCellId = this->InsertTriangle((vtkIdType *)pts); - } - else if (num == 2) - { - for (PointIdIterator it = t->PointIdsBegin(); it != t->PointIdsEnd(); it++) - pts[i++] = *it; - vtkCellId = this->InsertLine((vtkIdType *)pts); - } - - if (this->m_UseCellScalarAccessor && vtkCellId >= 0) - { - this->m_CellScalars->InsertTuple1(vtkCellId, ScalarAccessor::GetCellScalar(this->m_CellData, cellId)); - } - } - - /*! - Visit a hexahedron and create the VTK_HEXAHEDRON cell - */ - void Visit(unsigned long cellId, floatHexahedronCell *t) - { - vtkIdType pts[8]; - int i = 0; - unsigned long num = t->GetNumberOfVertices(); - vtkIdType vtkCellId = -1; - if (num == 8) - { - for (PointIdIterator it = t->PointIdsBegin(); it != t->PointIdsEnd(); it++) - { - if (i == 2) - pts[i++] = *(it + 1); - else if (i == 3) - pts[i++] = *(it - 1); - else if (i == 6) - pts[i++] = *(it + 1); - else if (i == 7) - pts[i++] = *(it - 1); - else - pts[i++] = *it; - } - vtkCellId = this->InsertHexahedron((vtkIdType *)pts); - } - else if (num == 4) - { - for (PointIdIterator it = t->PointIdsBegin(); it != t->PointIdsEnd(); it++) - pts[i++] = *it; - vtkCellId = this->InsertQuad((vtkIdType *)pts); - } - else if (num == 3) - { - for (PointIdIterator it = t->PointIdsBegin(); it != t->PointIdsEnd(); it++) - pts[i++] = *it; - vtkCellId = this->InsertTriangle((vtkIdType *)pts); - } - else if (num == 2) - { - for (PointIdIterator it = t->PointIdsBegin(); it != t->PointIdsEnd(); it++) - pts[i++] = *it; - vtkCellId = this->InsertLine((vtkIdType *)pts); - } - - if (this->m_UseCellScalarAccessor && vtkCellId >= 0) - { - this->m_CellScalars->InsertTuple1(vtkCellId, ScalarAccessor::GetCellScalar(this->m_CellData, cellId)); - } - } - }; - - /*! - \brief A visitor similar to SwitchByCellType, but with - exact matching of cell types - - Works as described in SwitchByCellType, but does exact - matching of cell types, e.g., for a polygon cell with just - two points, \em no insert-method will be called, because - a polygon must have at least three points. - \sa SwitchByCellType - \sa SingleCellArrayInsertImplementation - \sa DistributeInsertImplementation - */ - template <class InsertImplementation> - class ExactSwitchByCellType : public InsertImplementation - { - // typedef the itk cells we are interested in - typedef typename itk::CellInterface<typename MeshType::CellPixelType, typename MeshType::CellTraits> - CellInterfaceType; - typedef itk::LineCell<CellInterfaceType> floatLineCell; - typedef itk::TriangleCell<CellInterfaceType> floatTriangleCell; - typedef itk::PolygonCell<CellInterfaceType> floatPolygonCell; - typedef itk::QuadrilateralCell<CellInterfaceType> floatQuadrilateralCell; - typedef itk::TetrahedronCell<CellInterfaceType> floatTetrahedronCell; - typedef itk::HexahedronCell<CellInterfaceType> floatHexahedronCell; - typedef typename CellInterfaceType::PointIdConstIterator PointIdIterator; - - public: - /*! - Visit a line and create the VTK_LINE cell - */ - void Visit(unsigned long, floatLineCell *t) - { - unsigned long num = t->GetNumberOfVertices(); - vtkIdType pts[2]; - int i = 0; - - if (num == 2) - { - for (PointIdIterator it = t->PointIdsBegin(); it != t->PointIdsEnd(); it++) - pts[i++] = *it; - this->InsertLine(pts); - } - } - - /*! - Visit a polygon and create the VTK_POLYGON cell - */ - void Visit(unsigned long, floatPolygonCell *t) - { - vtkIdType pts[4096]; - unsigned long num = t->GetNumberOfVertices(); - if (num > 4096) - { - MITK_ERROR << "Problem in mitkMeshUtil: Polygon with more than maximum number of vertices encountered." - << std::endl; - } - int i = 0; - - if (num > 3) - { - for (PointIdIterator it = t->PointIdsBegin(); it != t->PointIdsEnd(); it++) - pts[i++] = *it; - this->InsertPolygon(num, pts); - } - } - - /*! - Visit a triangle and create the VTK_TRIANGLE cell - */ - void Visit(unsigned long, floatTriangleCell *t) - { - unsigned long num = t->GetNumberOfVertices(); - vtkIdType pts[3]; - int i = 0; - - if (num == 3) - { - for (PointIdIterator it = t->PointIdsBegin(); it != t->PointIdsEnd(); it++) - pts[i++] = *it; - this->InsertTriangle(pts); - } - } - - /*! - Visit a quadrilateral and create the VTK_QUAD cell - */ - void Visit(unsigned long, floatQuadrilateralCell *t) - { - unsigned long num = t->GetNumberOfVertices(); - vtkIdType pts[4]; - int i = 0; - - if (num == 4) - { - for (PointIdIterator it = t->PointIdsBegin(); it != t->PointIdsEnd(); it++) - pts[i++] = *it; - - vtkIdType tmpId = pts[2]; - pts[2] = pts[3]; - pts[3] = tmpId; - this->InsertQuad(pts); - } - } - - /*! - Visit a tetrahedron and create the VTK_TETRA cell - */ - void Visit(unsigned long, floatTetrahedronCell *t) - { - unsigned long num = t->GetNumberOfVertices(); - - vtkIdType pts[4]; - int i = 0; - - if (num == 4) - { - for (PointIdIterator it = t->PointIdsBegin(); it != t->PointIdsEnd(); it++) - pts[i++] = *it; - this->InsertTetra(pts); - } - } - - /*! - Visit a hexahedron and create the VTK_HEXAHEDRON cell - */ - void Visit(unsigned long, floatHexahedronCell *t) - { - unsigned long num = t->GetNumberOfVertices(); - vtkIdType pts[8]; - int i = 0; - - if (num == 8) - { - for (PointIdIterator it = t->PointIdsBegin(); it != t->PointIdsEnd(); it++) - pts[i++] = *it; - - vtkIdType tmp[8]; - for (unsigned int i = 0; i < 8; i++) - tmp[i] = pts[i]; - pts[2] = tmp[3]; - pts[3] = tmp[2]; - pts[6] = tmp[7]; - pts[7] = tmp[6]; - this->InsertHexahedron(pts); - } - } - }; - - /*! - \brief Implementation of the InsertImplementation interface of - SwitchByCellType to define a visitor that create cells - according to their types and put them in a single - vtkCellArray (for vtkUnstructuredGrid construction) - */ - class SingleCellArrayInsertImplementation - { - vtkCellArray *m_Cells; - int *m_TypeArray; - // vtkIdType cellId; - - protected: - bool m_UseCellScalarAccessor; - vtkFloatArray *m_CellScalars; - typename MeshType::CellDataContainer::Pointer m_CellData; - - public: - SingleCellArrayInsertImplementation() : m_UseCellScalarAccessor(false) {} - /*! Set the vtkCellArray that will be constructed - */ - void SetCellArray(vtkCellArray *cells) { m_Cells = cells; } - /*! - Set the type array for storing the vtk cell types - */ - void SetTypeArray(int *i) { m_TypeArray = i; } - void SetUseCellScalarAccessor(bool flag) { m_UseCellScalarAccessor = flag; } - void SetCellScalars(vtkFloatArray *scalars) { m_CellScalars = scalars; } - vtkFloatArray *GetCellScalars() { return m_CellScalars; } - void SetMeshCellData(typename MeshType::CellDataContainer *data) { m_CellData = data; } - vtkIdType InsertLine(vtkIdType *pts) - { - vtkIdType cellId = m_Cells->InsertNextCell(2, pts); - m_TypeArray[cellId] = VTK_LINE; - return cellId; - } - - vtkIdType InsertTriangle(vtkIdType *pts) - { - vtkIdType cellId = m_Cells->InsertNextCell(3, pts); - m_TypeArray[cellId] = VTK_TRIANGLE; - return cellId; - } - - vtkIdType InsertPolygon(vtkIdType npts, vtkIdType *pts) - { - vtkIdType cellId = m_Cells->InsertNextCell(npts, pts); - m_TypeArray[cellId] = VTK_POLYGON; - return cellId; - } - - vtkIdType InsertQuad(vtkIdType *pts) - { - vtkIdType cellId = m_Cells->InsertNextCell(4, pts); - m_TypeArray[cellId] = VTK_QUAD; - return cellId; - } - - vtkIdType InsertTetra(vtkIdType *pts) - { - vtkIdType cellId = m_Cells->InsertNextCell(4, pts); - m_TypeArray[cellId] = VTK_TETRA; - return cellId; - } - - vtkIdType InsertHexahedron(vtkIdType *pts) - { - vtkIdType cellId = m_Cells->InsertNextCell(8, pts); - m_TypeArray[cellId] = VTK_HEXAHEDRON; - return cellId; - } - }; - - /*! - \brief Implementation of the InsertImplementation interface of - SwitchByCellType to define a visitor that distributes cells - according to their types (for vtkPolyData construction) - */ - class DistributeInsertImplementation - { - vtkCellArray *m_LineCells; - vtkCellArray *m_TriangleCells; - vtkCellArray *m_PolygonCells; - vtkCellArray *m_QuadCells; - - protected: - bool m_UseCellScalarAccessor; - vtkFloatArray *m_CellScalars; - typename MeshType::CellDataContainer::Pointer m_CellData; - - public: - DistributeInsertImplementation() : m_UseCellScalarAccessor(false) {} - /*! Set the vtkCellArray that will be constructed - */ - void SetCellArrays(vtkCellArray *lines, vtkCellArray *triangles, vtkCellArray *polygons, vtkCellArray *quads) - { - m_LineCells = lines; - m_TriangleCells = triangles; - m_PolygonCells = polygons; - m_QuadCells = quads; - } - - vtkIdType InsertLine(vtkIdType *pts) { return m_LineCells->InsertNextCell(2, pts); } - vtkIdType InsertTriangle(vtkIdType *pts) { return m_TriangleCells->InsertNextCell(3, pts); } - vtkIdType InsertPolygon(vtkIdType npts, vtkIdType *pts) { return m_PolygonCells->InsertNextCell(npts, pts); } - vtkIdType InsertQuad(vtkIdType *pts) { return m_QuadCells->InsertNextCell(4, pts); } - vtkIdType InsertTetra(vtkIdType * /*pts*/) { return -1; } // ignored - vtkIdType InsertHexahedron(vtkIdType * /*pts*/) { return -1; } // ignored - }; - - // typedef typename MeshType::CellType CellType; - // typedef typename itk::LineCell< CellType > LineType; - // typedef typename itk::PolygonCell< CellType > PolygonType; - // typedef typename itk::TriangleCell< CellType > TriangleType; - - typedef SwitchByCellType<SingleCellArrayInsertImplementation> SingleCellArrayUserVisitorType; - typedef SwitchByCellType<DistributeInsertImplementation> DistributeUserVisitorType; - typedef ExactSwitchByCellType<DistributeInsertImplementation> ExactUserVisitorType; - -public: - typedef itk::MatrixOffsetTransformBase<typename MeshType::CoordRepType, 3, 3> ITKTransformType; - typedef itk::MatrixOffsetTransformBase<mitk::ScalarType, 3, 3> MITKTransformType; - - /*! - Convert a MITK transformation to an ITK transformation - Necessary because ITK uses double and MITK uses float values - */ - static void ConvertTransformToItk(const MITKTransformType *mitkTransform, ITKTransformType *itkTransform) - { - typename MITKTransformType::MatrixType mitkM = mitkTransform->GetMatrix(); - typename ITKTransformType::MatrixType itkM; - - typename MITKTransformType::OffsetType mitkO = mitkTransform->GetOffset(); - typename ITKTransformType::OffsetType itkO; - - for (short i = 0; i < 3; ++i) - { - for (short j = 0; j < 3; ++j) - { - itkM[i][j] = (double)mitkM[i][j]; - } - itkO[i] = (double)mitkO[i]; - } - - itkTransform->SetMatrix(itkM); - itkTransform->SetOffset(itkO); - } - - /*! - create an itkMesh object from a vtkPolyData - */ - static typename MeshType::Pointer MeshFromPolyData(vtkPolyData *poly, - mitk::BaseGeometry *geometryFrame = nullptr, - mitk::BaseGeometry *polyDataGeometryFrame = nullptr) - { - // Create a new mesh - typename MeshType::Pointer output = MeshType::New(); - output->SetCellsAllocationMethod(MeshType::CellsAllocatedDynamicallyCellByCell); - - typedef typename MeshType::CellDataContainer MeshCellDataContainerType; - - output->SetCellData(MeshCellDataContainerType::New()); - - // Get the points from vtk - vtkPoints *vtkpoints = poly->GetPoints(); - const unsigned int numPoints = poly->GetNumberOfPoints(); - - // Create a compatible point container for the mesh - // the mesh is created with a null points container - // MeshType::PointsContainer::Pointer points = - // MeshType::PointsContainer::New(); - // // Resize the point container to be able to fit the vtk points - // points->Reserve(numPoints); - // // Set the point container on the mesh - // output->SetPoints(points); - double vtkpoint[3]; - typename MeshType::PointType itkPhysicalPoint; - if (geometryFrame == nullptr) - { - if (polyDataGeometryFrame == nullptr) - { - for (unsigned int i = 0; i < numPoints; ++i) - { - vtkpoints->GetPoint(i, vtkpoint); - // MITK_INFO << "next point: " << test[0]<< "," << test[1] << "," << test[2] << std::endl; - // typename MeshType::PixelType* apoint = (typename MeshType::PixelType*) vtkpoints->GetPoint(i); - mitk::vtk2itk(vtkpoint, itkPhysicalPoint); - output->SetPoint(i, itkPhysicalPoint); - } - } - else - { - for (unsigned int i = 0; i < numPoints; ++i) - { - vtkpoints->GetPoint(i, vtkpoint); - // MITK_INFO << "next point: " << test[0]<< "," << test[1] << "," << test[2] << std::endl; - // typename MeshType::PixelType* apoint = (typename MeshType::PixelType*) vtkpoints->GetPoint(i); - mitk::Point3D mitkWorldPoint; - mitk::vtk2itk(vtkpoint, mitkWorldPoint); - polyDataGeometryFrame->IndexToWorld(mitkWorldPoint, mitkWorldPoint); - mitk::vtk2itk(mitkWorldPoint, itkPhysicalPoint); - output->SetPoint(i, itkPhysicalPoint); - } - } - } - else - { - mitk::Point3D mitkWorldPoint; - if (polyDataGeometryFrame == nullptr) - { - for (unsigned int i = 0; i < numPoints; ++i) - { - vtkpoints->GetPoint(i, vtkpoint); - // MITK_INFO << "next point: " << test[0]<< "," << test[1] << "," << test[2] << std::endl; - // typename MeshType::PixelType* apoint = (typename MeshType::PixelType*) vtkpoints->GetPoint(i); - mitk::vtk2itk(vtkpoint, mitkWorldPoint); - geometryFrame->WorldToItkPhysicalPoint(mitkWorldPoint, itkPhysicalPoint); - output->SetPoint(i, itkPhysicalPoint); - } - } - else - { - for (unsigned int i = 0; i < numPoints; ++i) - { - vtkpoints->GetPoint(i, vtkpoint); - // MITK_INFO << "next point: " << test[0]<< "," << test[1] << "," << test[2] << std::endl; - // typename MeshType::PixelType* apoint = (typename MeshType::PixelType*) vtkpoints->GetPoint(i); - mitk::vtk2itk(vtkpoint, mitkWorldPoint); - polyDataGeometryFrame->IndexToWorld(mitkWorldPoint, mitkWorldPoint); - geometryFrame->WorldToItkPhysicalPoint(mitkWorldPoint, itkPhysicalPoint); - output->SetPoint(i, itkPhysicalPoint); - } - } - } - - vtkCellArray *vtkcells = poly->GetPolys(); - // vtkCellArray* vtkcells = poly->GetStrips(); - // MeshType::CellsContainerPointer cells = MeshType::CellsContainer::New(); - // output->SetCells(cells); - // extract the cell id's from the vtkUnstructuredGrid - int numcells = vtkcells->GetNumberOfCells(); - int *vtkCellTypes = new int[numcells]; - int cellId = 0; - // poly ids start after verts and lines! - int cellIdOfs = poly->GetNumberOfVerts() + poly->GetNumberOfLines(); - for (; cellId < numcells; cellId++) - { - vtkCellTypes[cellId] = poly->GetCellType(cellId + cellIdOfs); - } - - // cells->Reserve(numcells); - vtkIdType npts; - vtkIdType *pts; - cellId = 0; - - typedef typename MeshType::MeshTraits OMeshTraits; - typedef typename OMeshTraits::PixelType OPixelType; - typedef typename MeshType::CellTraits CellTraits; - typedef typename itk::CellInterface<OPixelType, CellTraits> CellInterfaceType; - typedef typename itk::TriangleCell<CellInterfaceType> TriCellType; - typedef typename TriCellType::CellAutoPointer TriCellPointer; - - TriCellPointer newCell; - output->GetCells()->Reserve(poly->GetNumberOfPolys() + poly->GetNumberOfStrips()); - output->GetCellData()->Reserve(poly->GetNumberOfPolys() + poly->GetNumberOfStrips()); - - for (vtkcells->InitTraversal(); vtkcells->GetNextCell(npts, pts); cellId++) - { - switch (vtkCellTypes[cellId]) - { - case VTK_TRIANGLE: - { - if (npts != 3) - continue; // skip non-triangles; - itk::IdentifierType pointIds[3]; - pointIds[0] = (unsigned long)pts[0]; - pointIds[1] = (unsigned long)pts[1]; - pointIds[2] = (unsigned long)pts[2]; - - newCell.TakeOwnership(new TriCellType); - newCell->SetPointIds(pointIds); //(unsigned long*)pts); - output->SetCell(cellId, newCell); - output->SetCellData(cellId, (typename MeshType::PixelType)3); - break; - } - - case VTK_QUAD: - { - if (npts != 4) - continue; // skip non-quadrilateral - itk::IdentifierType pointIds[3]; - - pointIds[0] = (unsigned long)pts[0]; - pointIds[1] = (unsigned long)pts[1]; - pointIds[2] = (unsigned long)pts[2]; - newCell.TakeOwnership(new TriCellType); - newCell->SetPointIds(pointIds); - output->SetCell(cellId, newCell); - output->SetCellData(cellId, (typename MeshType::PixelType)3); - cellId++; - - pointIds[0] = (unsigned long)pts[2]; - pointIds[1] = (unsigned long)pts[3]; - pointIds[2] = (unsigned long)pts[0]; - newCell.TakeOwnership(new TriCellType); - newCell->SetPointIds(pointIds); - output->SetCell(cellId, newCell); - output->SetCellData(cellId, (typename MeshType::PixelType)3); - break; - } - - case VTK_EMPTY_CELL: - { - if (npts != 3) - { - MITK_ERROR << "Only empty triangle cell supported by now..." << std::endl; // skip non-triangle empty cells; - continue; - } - itk::IdentifierType pointIds[3]; - pointIds[0] = (unsigned long)pts[0]; - pointIds[1] = (unsigned long)pts[1]; - pointIds[2] = (unsigned long)pts[2]; - - newCell.TakeOwnership(new TriCellType); - newCell->SetPointIds(pointIds); - output->SetCell(cellId, newCell); - output->SetCellData(cellId, (typename MeshType::PixelType)3); - break; - } - - // case VTK_VERTEX: // If need to implement use - // case VTK_POLY_VERTEX: // the poly->GetVerts() and - // case VTK_LINE: // poly->GetLines() routines - // case VTK_POLY_LINE: // outside of the switch..case. - case VTK_POLYGON: - case VTK_PIXEL: - { - if (npts != 4) - continue; // skip non-quadrilateral - itk::IdentifierType pointIds[3]; - for (unsigned int idx = 0; idx <= 1; idx++) - { - pointIds[0] = (unsigned long)pts[idx]; - pointIds[1] = (unsigned long)pts[idx + 1]; - pointIds[2] = (unsigned long)pts[idx + 2]; - newCell.TakeOwnership(new TriCellType); - newCell->SetPointIds(pointIds); - output->SetCell(cellId + idx, newCell); - output->SetCellData(cellId + idx, (typename MeshType::PixelType)3); - } - cellId++; - break; - } - - case VTK_TETRA: - case VTK_VOXEL: - case VTK_HEXAHEDRON: - case VTK_WEDGE: - case VTK_PYRAMID: - case VTK_PARAMETRIC_CURVE: - case VTK_PARAMETRIC_SURFACE: - default: - MITK_WARN << "Warning, unhandled cell type " << vtkCellTypes[cellId] << std::endl; - } - } - - if (poly->GetNumberOfStrips() != 0) - { - vtkcells = poly->GetStrips(); - numcells = vtkcells->GetNumberOfCells(); - vtkCellTypes = new int[numcells]; - int stripId = 0; - // strip ids start after verts, lines and polys! - int stripIdOfs = poly->GetNumberOfVerts() + poly->GetNumberOfLines() + poly->GetNumberOfPolys(); - for (; stripId < numcells; stripId++) - { - vtkCellTypes[stripId] = poly->GetCellType(stripId + stripIdOfs); - } - stripId = 0; - - vtkcells->InitTraversal(); - while (vtkcells->GetNextCell(npts, pts)) - { - if (vtkCellTypes[stripId] != VTK_TRIANGLE_STRIP) - { - MITK_ERROR << "Only triangle strips supported!" << std::endl; - continue; - } - stripId++; - - unsigned int numberOfTrianglesInStrip = npts - 2; - itk::IdentifierType pointIds[3]; - pointIds[0] = (unsigned long)pts[0]; - pointIds[1] = (unsigned long)pts[1]; - pointIds[2] = (unsigned long)pts[2]; - - for (unsigned int t = 0; t < numberOfTrianglesInStrip; t++) - { - newCell.TakeOwnership(new TriCellType); - newCell->SetPointIds(pointIds); - output->SetCell(cellId, newCell); - output->SetCellData(cellId, (typename MeshType::PixelType)3); - cellId++; - pointIds[0] = pointIds[1]; - pointIds[1] = pointIds[2]; - pointIds[2] = pts[t + 3]; - } - } - } - // output->Print(std::cout); - output->BuildCellLinks(); - delete[] vtkCellTypes; - return output; - } - - /*! - create an itkMesh object from an mitk::Surface - */ - static typename MeshType::Pointer MeshFromSurface(mitk::Surface *surface, mitk::BaseGeometry *geometryFrame = nullptr) - { - if (surface == nullptr) - return nullptr; - return MeshFromPolyData(surface->GetVtkPolyData(), geometryFrame, surface->GetGeometry()); - } - - /*! - create an vtkUnstructuredGrid object from an itkMesh - */ - static vtkUnstructuredGrid *MeshToUnstructuredGrid(MeshType *mesh, - bool usePointScalarAccessor = false, - bool useCellScalarAccessor = false, - unsigned int pointDataType = 0, - mitk::BaseGeometry *geometryFrame = nullptr) - { - /*! - default SingleCellArray line cell visitior definition - */ - typedef typename itk::CellInterfaceVisitorImplementation<typename MeshType::CellPixelType, - typename MeshType::CellTraits, - itk::LineCell<typename MeshType::CellType>, - SingleCellArrayUserVisitorType> - SingleCellArrayLineVisitor; - - /*! - default SingleCellArray polygon cell visitior definition - */ - typedef typename itk::CellInterfaceVisitorImplementation<typename MeshType::CellPixelType, - typename MeshType::CellTraits, - itk::PolygonCell<typename MeshType::CellType>, - SingleCellArrayUserVisitorType> - SingleCellArrayPolygonVisitor; - - /*! - default SingleCellArray triangle cell visitior definition - */ - typedef typename itk::CellInterfaceVisitorImplementation< - typename MeshType::CellPixelType, - typename MeshType::CellTraits, - itk::TriangleCell<itk::CellInterface<typename MeshType::CellPixelType, typename MeshType::CellTraits>>, - SingleCellArrayUserVisitorType> - SingleCellArrayTriangleVisitor; - - /*! - default SingleCellArray quad cell visitior definition - */ - typedef typename itk::CellInterfaceVisitorImplementation< - typename MeshType::CellPixelType, - typename MeshType::CellTraits, - itk::QuadrilateralCell<itk::CellInterface<typename MeshType::CellPixelType, typename MeshType::CellTraits>>, - SingleCellArrayUserVisitorType> - SingleCellArrayQuadrilateralVisitor; - - /*! - default SingleCellArray tetra cell visitior definition - */ - typedef typename itk::CellInterfaceVisitorImplementation< - typename MeshType::CellPixelType, - typename MeshType::CellTraits, - itk::TetrahedronCell<itk::CellInterface<typename MeshType::CellPixelType, typename MeshType::CellTraits>>, - SingleCellArrayUserVisitorType> - SingleCellArrayTetrahedronVisitor; - - /*! - default SingleCellArray hex cell visitior definition - */ - typedef typename itk::CellInterfaceVisitorImplementation< - typename MeshType::CellPixelType, - typename MeshType::CellTraits, - itk::HexahedronCell<itk::CellInterface<typename MeshType::CellPixelType, typename MeshType::CellTraits>>, - SingleCellArrayUserVisitorType> - SingleCellArrayHexahedronVisitor; - - // Get the number of points in the mesh - int numPoints = mesh->GetNumberOfPoints(); - if (numPoints == 0) - { - // mesh->Print(std::cerr); - MITK_FATAL << "no points in Grid " << std::endl; - exit(-1); - } - // Create a vtkUnstructuredGrid - vtkUnstructuredGrid *vgrid = vtkUnstructuredGrid::New(); - // Create the vtkPoints object and set the number of points - vtkPoints *vpoints = vtkPoints::New(VTK_DOUBLE); - - vtkFloatArray *pointScalars = vtkFloatArray::New(); - vtkFloatArray *cellScalars = vtkFloatArray::New(); - pointScalars->SetNumberOfComponents(1); - cellScalars->SetNumberOfComponents(1); - - typename MeshType::PointsContainer::Pointer points = mesh->GetPoints(); - typename MeshType::PointsContainer::Iterator i; - - // iterate over all the points in the itk mesh to find - // the maximal index - unsigned int maxIndex = 0; - for (i = points->Begin(); i != points->End(); ++i) - { - if (maxIndex < i->Index()) - maxIndex = i->Index(); - } - - // initialize vtk-classes for points and scalars - vpoints->SetNumberOfPoints(maxIndex + 1); - pointScalars->SetNumberOfTuples(maxIndex + 1); - cellScalars->SetNumberOfTuples(mesh->GetNumberOfCells()); - - double vtkpoint[3]; - typename MeshType::PointType itkPhysicalPoint; - if (geometryFrame == nullptr) - { - for (i = points->Begin(); i != points->End(); ++i) - { - // Get the point index from the point container iterator - int idx = i->Index(); - - itkPhysicalPoint = i->Value(); - mitk::itk2vtk(itkPhysicalPoint, vtkpoint); - // Set the vtk point at the index with the the coord array from itk - vpoints->SetPoint(idx, vtkpoint); - - if (usePointScalarAccessor) - { - pointScalars->InsertTuple1( - idx, ScalarAccessor::GetPointScalar(mesh->GetPointData(), i->Index(), mesh, pointDataType)); - } - } - } - else - { - mitk::Point3D mitkWorldPoint; - for (i = points->Begin(); i != points->End(); ++i) - { - // Get the point index from the point container iterator - int idx = i->Index(); - - itkPhysicalPoint = i->Value(); - geometryFrame->ItkPhysicalPointToWorld(itkPhysicalPoint, mitkWorldPoint); - mitk::itk2vtk(mitkWorldPoint, vtkpoint); - // Set the vtk point at the index with the the coord array from itk - vpoints->SetPoint(idx, vtkpoint); - - if (usePointScalarAccessor) - { - pointScalars->InsertTuple1( - idx, ScalarAccessor::GetPointScalar(mesh->GetPointData(), i->Index(), mesh, pointDataType)); - } - } - } - // Set the points on the vtk grid - vgrid->SetPoints(vpoints); - if (usePointScalarAccessor) - vgrid->GetPointData()->SetScalars(pointScalars); - - // Now create the cells using the MultiVisitor - // 1. Create a MultiVisitor - typename MeshType::CellType::MultiVisitor::Pointer mv = MeshType::CellType::MultiVisitor::New(); - // 2. Create visitors - typename SingleCellArrayLineVisitor::Pointer lv = SingleCellArrayLineVisitor::New(); - typename SingleCellArrayPolygonVisitor::Pointer pv = SingleCellArrayPolygonVisitor::New(); - typename SingleCellArrayTriangleVisitor::Pointer tv = SingleCellArrayTriangleVisitor::New(); - typename SingleCellArrayQuadrilateralVisitor::Pointer qv = SingleCellArrayQuadrilateralVisitor::New(); - typename SingleCellArrayTetrahedronVisitor::Pointer tetv = SingleCellArrayTetrahedronVisitor::New(); - typename SingleCellArrayHexahedronVisitor::Pointer hv = SingleCellArrayHexahedronVisitor::New(); - // 3. Set up the visitors - // int vtkCellCount = 0; // running counter for current cell being inserted into vtk - int numCells = mesh->GetNumberOfCells(); - int *types = new int[numCells]; // type array for vtk - // create vtk cells and estimate the size - vtkCellArray *cells = vtkCellArray::New(); - cells->Allocate(numCells); - // Set the TypeArray CellCount and CellArray for the visitors - lv->SetTypeArray(types); - lv->SetCellArray(cells); - pv->SetTypeArray(types); - pv->SetCellArray(cells); - tv->SetTypeArray(types); - // tv->SetCellCounter(&vtkCellCount); - tv->SetCellArray(cells); - qv->SetTypeArray(types); - // qv->SetCellCounter(&vtkCellCount); - qv->SetCellArray(cells); - tetv->SetTypeArray(types); - tetv->SetCellArray(cells); - hv->SetTypeArray(types); - hv->SetCellArray(cells); - - if (useCellScalarAccessor) - { - lv->SetUseCellScalarAccessor(true); - lv->SetCellScalars(cellScalars); - lv->SetMeshCellData(mesh->GetCellData()); - - pv->SetUseCellScalarAccessor(true); - pv->SetCellScalars(cellScalars); - pv->SetMeshCellData(mesh->GetCellData()); - - tv->SetUseCellScalarAccessor(true); - tv->SetCellScalars(cellScalars); - tv->SetMeshCellData(mesh->GetCellData()); - - qv->SetUseCellScalarAccessor(true); - qv->SetCellScalars(cellScalars); - qv->SetMeshCellData(mesh->GetCellData()); - - tetv->SetUseCellScalarAccessor(true); - tetv->SetCellScalars(cellScalars); - tetv->SetMeshCellData(mesh->GetCellData()); - - hv->SetUseCellScalarAccessor(true); - hv->SetCellScalars(cellScalars); - hv->SetMeshCellData(mesh->GetCellData()); - } - - // add the visitors to the multivisitor - mv->AddVisitor(lv); - mv->AddVisitor(pv); - mv->AddVisitor(tv); - mv->AddVisitor(qv); - mv->AddVisitor(tetv); - mv->AddVisitor(hv); - // Now ask the mesh to accept the multivisitor which - // will Call Visit for each cell in the mesh that matches the - // cell types of the visitors added to the MultiVisitor - mesh->Accept(mv); - // Now set the cells on the vtk grid with the type array and cell array - - vgrid->SetCells(types, cells); - vgrid->GetCellData()->SetScalars(cellScalars); - - // Clean up vtk objects (no vtkSmartPointer ... ) - cells->Delete(); - vpoints->Delete(); - delete[] types; - - pointScalars->Delete(); - cellScalars->Delete(); - // MITK_INFO << "meshToUnstructuredGrid end" << std::endl; - return vgrid; - } - - /*! - create a vtkPolyData object from an itkMesh - */ - static vtkPolyData *MeshToPolyData(MeshType *mesh, - bool onlyTriangles = false, - bool useScalarAccessor = false, - unsigned int pointDataType = 0, - mitk::BaseGeometry *geometryFrame = nullptr, - vtkPolyData *polydata = nullptr) - { - /*! - default Distribute line cell visitior definition - */ - typedef typename itk::CellInterfaceVisitorImplementation<typename MeshType::CellPixelType, - typename MeshType::CellTraits, - itk::LineCell<typename MeshType::CellType>, - DistributeUserVisitorType> - DistributeLineVisitor; - - /*! - default Distribute polygon cell visitior definition - */ - typedef typename itk::CellInterfaceVisitorImplementation<typename MeshType::CellPixelType, - typename MeshType::CellTraits, - itk::PolygonCell<typename MeshType::CellType>, - DistributeUserVisitorType> - DistributePolygonVisitor; - - /*! - default Distribute triangle cell visitior definition - */ - typedef typename itk::CellInterfaceVisitorImplementation< - typename MeshType::CellPixelType, - typename MeshType::CellTraits, - itk::TriangleCell<itk::CellInterface<typename MeshType::CellPixelType, typename MeshType::CellTraits>>, - DistributeUserVisitorType> - DistributeTriangleVisitor; - - /*! - default Distribute quad cell visitior definition - */ - typedef typename itk::CellInterfaceVisitorImplementation< - typename MeshType::CellPixelType, - typename MeshType::CellTraits, - itk::QuadrilateralCell<itk::CellInterface<typename MeshType::CellPixelType, typename MeshType::CellTraits>>, - DistributeUserVisitorType> - DistributeQuadrilateralVisitor; - - /*! - default Distribute triangle cell visitior definition - */ - typedef typename itk::CellInterfaceVisitorImplementation< - typename MeshType::CellPixelType, - typename MeshType::CellTraits, - itk::TriangleCell<itk::CellInterface<typename MeshType::CellPixelType, typename MeshType::CellTraits>>, - ExactUserVisitorType> - ExactTriangleVisitor; - - // Get the number of points in the mesh - int numPoints = mesh->GetNumberOfPoints(); - if (numPoints == 0) - { - // mesh->Print(std::cerr); - MITK_ERROR << "no points in Grid " << std::endl; - } - // Create a vtkPolyData - if (polydata == nullptr) - polydata = vtkPolyData::New(); - else - polydata->Initialize(); - - // Create the vtkPoints object and set the number of points - vtkPoints *vpoints = vtkPoints::New(VTK_DOUBLE); - - vtkFloatArray *scalars = vtkFloatArray::New(); - scalars->SetNumberOfComponents(1); - - typename MeshType::PointsContainer::Pointer points = mesh->GetPoints(); - typename MeshType::PointsContainer::Iterator i; - - // iterate over all the points in the itk mesh to find - // the maximal index - unsigned int maxIndex = 0; - for (i = points->Begin(); i != points->End(); ++i) - { - if (maxIndex < i->Index()) - maxIndex = i->Index(); - } - - // initialize vtk-classes for points and scalars - vpoints->SetNumberOfPoints(maxIndex + 1); - scalars->SetNumberOfTuples(maxIndex + 1); - - // iterate over all the points in the itk mesh filling in - // the vtkPoints object as we go - - double vtkpoint[3]; - typename MeshType::PointType itkPhysicalPoint; - if (geometryFrame == nullptr) - { - for (i = points->Begin(); i != points->End(); ++i) - { - // Get the point index from the point container iterator - int idx = i->Index(); - - itkPhysicalPoint = i->Value(); - mitk::itk2vtk(itkPhysicalPoint, vtkpoint); - // Set the vtk point at the index with the the coord array from itk - // itk returns a const pointer, but vtk is not const correct, so - // we have to use a const cast to get rid of the const - // vpoints->SetPoint(idx, const_cast<DATATYPE*>(i->Value().GetDataPointer())); - vpoints->SetPoint(idx, vtkpoint); - - if (useScalarAccessor) - { - scalars->InsertTuple1(idx, - ScalarAccessor::GetPointScalar(mesh->GetPointData(), i->Index(), mesh, pointDataType)); - } - } - } - else - { - mitk::Point3D mitkWorldPoint; - for (i = points->Begin(); i != points->End(); ++i) - { - // Get the point index from the point container iterator - int idx = i->Index(); - - itkPhysicalPoint = i->Value(); - geometryFrame->ItkPhysicalPointToWorld(itkPhysicalPoint, mitkWorldPoint); - mitk::itk2vtk(mitkWorldPoint, vtkpoint); - // Set the vtk point at the index with the the coord array from itk - // itk returns a const pointer, but vtk is not const correct, so - // we have to use a const cast to get rid of the const - // vpoints->SetPoint(idx, const_cast<DATATYPE*>(i->Value().GetDataPointer())); - vpoints->SetPoint(idx, vtkpoint); - - if (useScalarAccessor) - { - scalars->InsertTuple1(idx, - ScalarAccessor::GetPointScalar(mesh->GetPointData(), i->Index(), mesh, pointDataType)); - } - } - } - - // Set the points on the vtk grid - polydata->SetPoints(vpoints); - if (useScalarAccessor) - polydata->GetPointData()->SetScalars(scalars); - polydata->GetPointData()->CopyAllOn(); - - // Now create the cells using the MulitVisitor - // 1. Create a MultiVisitor - typedef typename MeshType::CellType::MultiVisitor MeshMV; - typename MeshMV::Pointer mv = MeshMV::New(); - - int numCells = mesh->GetNumberOfCells(); - - if (onlyTriangles) - { - // create vtk cells and allocate - vtkCellArray *trianglecells = vtkCellArray::New(); - trianglecells->Allocate(numCells); - - // 2. Create a triangle visitor and add it to the multivisitor - typename ExactTriangleVisitor::Pointer tv = ExactTriangleVisitor::New(); - tv->SetCellArrays(nullptr, trianglecells, nullptr, nullptr); - mv->AddVisitor(tv); - // 3. Now ask the mesh to accept the multivisitor which - // will Call Visit for each cell in the mesh that matches the - // cell types of the visitors added to the MultiVisitor - mesh->Accept(mv); - - // 4. Set the result into our vtkPolyData - if (trianglecells->GetNumberOfCells() > 0) - polydata->SetStrips(trianglecells); - - // 5. Clean up vtk objects (no vtkSmartPointer ... ) - trianglecells->Delete(); - } - else - { - // create vtk cells and allocate - vtkCellArray *linecells = vtkCellArray::New(); - vtkCellArray *trianglecells = vtkCellArray::New(); - vtkCellArray *polygoncells = vtkCellArray::New(); - linecells->Allocate(numCells); - trianglecells->Allocate(numCells); - polygoncells->Allocate(numCells); - - // 2. Create visitors - typename DistributeLineVisitor::Pointer lv = DistributeLineVisitor::New(); - typename DistributePolygonVisitor::Pointer pv = DistributePolygonVisitor::New(); - typename DistributeTriangleVisitor::Pointer tv = DistributeTriangleVisitor::New(); - typename DistributeQuadrilateralVisitor::Pointer qv = DistributeQuadrilateralVisitor::New(); - - lv->SetCellArrays(linecells, trianglecells, polygoncells, polygoncells); - pv->SetCellArrays(linecells, trianglecells, polygoncells, polygoncells); - tv->SetCellArrays(linecells, trianglecells, polygoncells, polygoncells); - qv->SetCellArrays(linecells, trianglecells, polygoncells, polygoncells); - - // add the visitors to the multivisitor - mv->AddVisitor(tv); - mv->AddVisitor(lv); - mv->AddVisitor(pv); - mv->AddVisitor(qv); - // 3. Now ask the mesh to accept the multivisitor which - // will Call Visit for each cell in the mesh that matches the - // cell types of the visitors added to the MultiVisitor - mesh->Accept(mv); - - // 4. Set the result into our vtkPolyData - if (linecells->GetNumberOfCells() > 0) - polydata->SetLines(linecells); - if (trianglecells->GetNumberOfCells() > 0) - polydata->SetStrips(trianglecells); - if (polygoncells->GetNumberOfCells() > 0) - polydata->SetPolys(polygoncells); - - // 5. Clean up vtk objects (no vtkSmartPointer ... ) - linecells->Delete(); - trianglecells->Delete(); - polygoncells->Delete(); - } - vpoints->Delete(); - scalars->Delete(); - - // MITK_INFO << "meshToPolyData end" << std::endl; - return polydata; - } - - static typename MeshType::Pointer CreateRegularSphereMesh(typename MeshType::PointType center, - typename MeshType::PointType::VectorType scale, - int resolution) - { - typedef itk::RegularSphereMeshSource<MeshType> SphereSourceType; - typename SphereSourceType::Pointer mySphereSource = SphereSourceType::New(); - - mySphereSource->SetCenter(center); - mySphereSource->SetScale(scale); - mySphereSource->SetResolution(resolution); - mySphereSource->Update(); - - typename MeshType::Pointer resultMesh = mySphereSource->GetOutput(); - resultMesh->Register(); // necessary ???? - return resultMesh; - } - - static typename MeshType::Pointer CreateSphereMesh(typename MeshType::PointType center, - typename MeshType::PointType scale, - int *resolution) - { - typedef typename itk::SphereMeshSource<MeshType> SphereSource; - - typename SphereSource::Pointer mySphereSource = SphereSource::New(); - - mySphereSource->SetCenter(center); - mySphereSource->SetScale(scale); - mySphereSource->SetResolutionX(resolution[0]); - mySphereSource->SetResolutionY(resolution[1]); - mySphereSource->SetSquareness1(1); - mySphereSource->SetSquareness2(1); - mySphereSource->Update(); - mySphereSource->GetOutput(); - - typename MeshType::Pointer resultMesh = mySphereSource->GetOutput(); - resultMesh->Register(); - - return resultMesh; - } - - // static typename MeshType::Pointer TranslateMesh(typename MeshType::PointType vec, MeshType* input) - // { - // - // typename MeshType::Pointer output = MeshType::New(); - // { - // output->SetPoints(input->GetPoints()); - // output->SetPointData(input->GetPointData()); - // output->SetCells(input->GetCells()); - // output->SetLastCellId( input->GetLastCellId() ); - // typename MeshType::GeometryMapIterator pointDataIterator = input->GetGeometryData()->Begin(); - // typename MeshType::GeometryMapIterator pointDataEnd = input->GetGeometryData()->End(); - // - // typename MeshType::PointType inputPoint,outputPoint; - // - // while (pointDataIterator != pointDataEnd) - // { - // unsigned long pointId = pointDataIterator->Index(); - // itk::SimplexMeshGeometry* newGeometry = new itk::SimplexMeshGeometry(); - // itk::SimplexMeshGeometry* refGeometry = pointDataIterator->Value(); - // - // input->GetPoint(pointId, &inputPoint ); - // outputPoint[0] = inputPoint[0] + vec[0]; - // outputPoint[1] = inputPoint[1] + vec[1]; - // outputPoint[2] = inputPoint[2] + vec[2]; - // output->SetPoint( pointId, outputPoint ); - // - // - // newGeometry->pos = outputPoint; - // newGeometry->neighborIndices = refGeometry->neighborIndices; - // newGeometry->meanCurvature = refGeometry->meanCurvature; - // newGeometry->neighbors = refGeometry->neighbors; - // newGeometry->oldPos = refGeometry->oldPos; - // newGeometry->eps = refGeometry->eps; - // newGeometry->referenceMetrics = refGeometry->referenceMetrics; - // newGeometry->neighborSet = refGeometry->neighborSet; - // newGeometry->distance = refGeometry->distance; - // newGeometry->externalForce = refGeometry->externalForce; - // newGeometry->internalForce = refGeometry->internalForce; - // output->SetGeometryData(pointId, newGeometry); - // pointDataIterator++; - // } - // } - //// output->SetGeometryData( inputMesh->GetGeometryData() ); - // return output; - // } - - static typename MeshType::Pointer CreateRegularSphereMesh2(typename MeshType::PointType center, - typename MeshType::PointType scale, - int resolution) - { - typedef typename itk::AutomaticTopologyMeshSource<MeshType> MeshSourceType; - typename MeshSourceType::Pointer mySphereSource = MeshSourceType::New(); - - typename MeshType::PointType pnt0, pnt1, pnt2, pnt3, pnt4, pnt5, pnt6, pnt7, pnt8, pnt9, pnt10, pnt11; - double c1 = 0.5 * (1.0 + sqrt(5.0)); - double c2 = 1.0; - double len = sqrt(c1 * c1 + c2 * c2); - c1 /= len; - c2 /= len; - - pnt0[0] = center[0] - c1 * scale[0]; - pnt0[1] = center[1]; - pnt0[2] = center[2] + c2 * scale[2]; - pnt1[0] = center[0]; - pnt1[1] = center[1] + c2 * scale[1]; - pnt1[2] = center[2] - c1 * scale[2]; - pnt2[0] = center[0]; - pnt2[1] = center[1] + c2 * scale[1]; - pnt2[2] = center[2] + c1 * scale[2]; - pnt3[0] = center[0] + c1 * scale[0]; - pnt3[1] = center[1]; - pnt3[2] = center[2] - c2 * scale[2]; - pnt4[0] = center[0] - c2 * scale[0]; - pnt4[1] = center[1] - c1 * scale[1]; - pnt4[2] = center[2]; - pnt5[0] = center[0] - c2 * scale[0]; - pnt5[1] = center[1] + c1 * scale[1]; - pnt5[2] = center[2]; - pnt6[0] = center[0]; - pnt6[1] = center[1] - c2 * scale[1]; - pnt6[2] = center[2] + c1 * scale[2]; - pnt7[0] = center[0] + c2 * scale[0]; - pnt7[1] = center[1] + c1 * scale[1]; - pnt7[2] = center[2]; - pnt8[0] = center[0]; - pnt8[1] = center[1] - c2 * scale[1]; - pnt8[2] = center[2] - c1 * scale[2]; - pnt9[0] = center[0] + c1 * scale[0]; - pnt9[1] = center[1]; - pnt9[2] = center[2] + c2 * scale[2]; - pnt10[0] = center[0] + c2 * scale[0]; - pnt10[1] = center[1] - c1 * scale[1]; - pnt10[2] = center[2]; - pnt11[0] = center[0] - c1 * scale[0]; - pnt11[1] = center[1]; - pnt11[2] = center[2] - c2 * scale[2]; - - addTriangle(mySphereSource, scale, pnt9, pnt2, pnt6, resolution); - addTriangle(mySphereSource, scale, pnt1, pnt11, pnt5, resolution); - addTriangle(mySphereSource, scale, pnt11, pnt1, pnt8, resolution); - addTriangle(mySphereSource, scale, pnt0, pnt11, pnt4, resolution); - addTriangle(mySphereSource, scale, pnt3, pnt1, pnt7, resolution); - addTriangle(mySphereSource, scale, pnt3, pnt8, pnt1, resolution); - addTriangle(mySphereSource, scale, pnt9, pnt3, pnt7, resolution); - addTriangle(mySphereSource, scale, pnt0, pnt6, pnt2, resolution); - addTriangle(mySphereSource, scale, pnt4, pnt10, pnt6, resolution); - addTriangle(mySphereSource, scale, pnt1, pnt5, pnt7, resolution); - addTriangle(mySphereSource, scale, pnt7, pnt5, pnt2, resolution); - addTriangle(mySphereSource, scale, pnt8, pnt3, pnt10, resolution); - addTriangle(mySphereSource, scale, pnt4, pnt11, pnt8, resolution); - addTriangle(mySphereSource, scale, pnt9, pnt7, pnt2, resolution); - addTriangle(mySphereSource, scale, pnt10, pnt9, pnt6, resolution); - addTriangle(mySphereSource, scale, pnt0, pnt5, pnt11, resolution); - addTriangle(mySphereSource, scale, pnt0, pnt2, pnt5, resolution); - addTriangle(mySphereSource, scale, pnt8, pnt10, pnt4, resolution); - addTriangle(mySphereSource, scale, pnt3, pnt9, pnt10, resolution); - addTriangle(mySphereSource, scale, pnt6, pnt0, pnt4, resolution); - - return mySphereSource->GetOutput(); - } - -private: - static void addTriangle(typename itk::AutomaticTopologyMeshSource<MeshType>::Pointer meshSource, - typename MeshType::PointType scale, - typename MeshType::PointType pnt0, - typename MeshType::PointType pnt1, - typename MeshType::PointType pnt2, - int resolution) - { - if (resolution == 0) - { - // add triangle - meshSource->AddTriangle(meshSource->AddPoint(pnt0), meshSource->AddPoint(pnt1), meshSource->AddPoint(pnt2)); - } - else - { - vnl_vector_fixed<typename MeshType::CoordRepType, 3> v1, v2, res, pv; - v1 = (pnt1 - pnt0).Get_vnl_vector(); - v2 = (pnt2 - pnt0).Get_vnl_vector(); - res = vnl_cross_3d(v1, v2); - pv = pnt0.GetVectorFromOrigin().Get_vnl_vector(); - // double d = res[0]*pv[0] + res[1]*pv[1] + res[2]*pv[2]; - - // subdivision - typename MeshType::PointType pnt01, pnt12, pnt20; - for (int d = 0; d < 3; d++) - { - pnt01[d] = (pnt0[d] + pnt1[d]) / 2.0; - pnt12[d] = (pnt1[d] + pnt2[d]) / 2.0; - pnt20[d] = (pnt2[d] + pnt0[d]) / 2.0; - } - // map new points to sphere - double lenPnt01 = 0; - for (int d = 0; d < 3; d++) - lenPnt01 += pnt01[d] * pnt01[d]; - lenPnt01 = sqrt(lenPnt01); - double lenPnt12 = 0; - for (int d = 0; d < 3; d++) - lenPnt12 += pnt12[d] * pnt12[d]; - lenPnt12 = sqrt(lenPnt12); - double lenPnt20 = 0; - for (int d = 0; d < 3; d++) - lenPnt20 += pnt20[d] * pnt20[d]; - lenPnt20 = sqrt(lenPnt20); - for (int d = 0; d < 3; d++) - { - pnt01[d] *= scale[d] / lenPnt01; - pnt12[d] *= scale[d] / lenPnt12; - pnt20[d] *= scale[d] / lenPnt20; - } - addTriangle(meshSource, scale, pnt0, pnt01, pnt20, resolution - 1); - addTriangle(meshSource, scale, pnt01, pnt1, pnt12, resolution - 1); - addTriangle(meshSource, scale, pnt20, pnt12, pnt2, resolution - 1); - addTriangle(meshSource, scale, pnt01, pnt12, pnt20, resolution - 1); - } - } -}; - -#endif // MITKMESHUTIL_H_INCLUDED diff --git a/Modules/DataTypesExt/src/mitkMesh.cpp b/Modules/DataTypesExt/src/mitkMesh.cpp deleted file mode 100644 index b88524fc13..0000000000 --- a/Modules/DataTypesExt/src/mitkMesh.cpp +++ /dev/null @@ -1,805 +0,0 @@ -/*============================================================================ - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center (DKFZ) -All rights reserved. - -Use of this source code is governed by a 3-clause BSD license that can be -found in the LICENSE file. - -============================================================================*/ - -#include "mitkMesh.h" -#include "mitkInteractionConst.h" -#include "mitkLine.h" -#include "mitkLineOperation.h" -#include "mitkLineOperation.h" -#include "mitkNumericTypes.h" -#include "mitkOperation.h" -#include "mitkOperationActor.h" -#include "mitkPointOperation.h" -#include "mitkRenderingManager.h" -#include "mitkStatusBar.h" - -mitk::Mesh::Mesh() -{ -} - -mitk::Mesh::~Mesh() -{ -} - -const mitk::Mesh::DataType *mitk::Mesh::GetMesh(int t) const -{ - return m_PointSetSeries[t]; -} - -mitk::Mesh::DataType *mitk::Mesh::GetMesh(int t) -{ - return m_PointSetSeries[t]; -} - -void mitk::Mesh::SetMesh(DataType *mesh, int t) -{ - this->Expand(t + 1); - m_PointSetSeries[t] = mesh; -} - -unsigned long mitk::Mesh::GetNumberOfCells(int t) -{ - return m_PointSetSeries[t]->GetNumberOfCells(); -} - -// search a line that is close enough according to the given position -bool mitk::Mesh::SearchLine(Point3D point, float distance, unsigned long &lineId, unsigned long &cellId, int t) -{ - // returns true if a line is found - ScalarType bestDist = distance; - - // iterate through all cells. - ConstCellIterator cellIt = m_PointSetSeries[t]->GetCells()->Begin(); - ConstCellIterator cellEnd = m_PointSetSeries[t]->GetCells()->End(); - while (cellIt != cellEnd) - { - if (cellIt.Value()->GetNumberOfPoints() > 1) - { - // then iterate through all indexes of points in it->Value() - PointIdIterator inAIt = cellIt.Value()->PointIdsBegin(); // first point - PointIdIterator inBIt = cellIt.Value()->PointIdsBegin(); // second point - PointIdIterator inEnd = cellIt.Value()->PointIdsEnd(); - - ++inAIt; // so it points to the point before inBIt - - int currentLineId = 0; - while (inAIt != inEnd) - { - mitk::PointSet::PointType pointA, pointB; - if (m_PointSetSeries[t]->GetPoint((*inAIt), &pointA) && m_PointSetSeries[t]->GetPoint((*inBIt), &pointB)) - { - auto line = new Line<CoordinateType>(); - line->SetPoints(pointA, pointB); - double thisDistance = line->Distance(point); - if (thisDistance < bestDist) - { - cellId = cellIt->Index(); - lineId = currentLineId; - bestDist = thisDistance; - } - } - ++inAIt; - ++inBIt; - ++currentLineId; - } - - // If the cell is closed, then check the line from the last index to - // the first index if inAIt points to inEnd, then inBIt points to the - // last index. - CellDataType cellData; - bool dataOk = m_PointSetSeries[t]->GetCellData(cellIt->Index(), &cellData); - if (dataOk) - { - if (cellData.closed) - { - // get the points - PointIdIterator inAIt = cellIt.Value()->PointIdsBegin(); // first point - // inBIt points to last. - mitk::PointSet::PointType pointA, pointB; - if (m_PointSetSeries[t]->GetPoint((*inAIt), &pointA) && m_PointSetSeries[t]->GetPoint((*inBIt), &pointB)) - { - auto line = new Line<CoordinateType>(); - line->SetPoints(pointA, pointB); - double thisDistance = line->Distance(point); - if (thisDistance < bestDist) - { - cellId = cellIt->Index(); - lineId = currentLineId; - bestDist = thisDistance; - } - } - } - } - } - ++cellIt; - } - return (bestDist < distance); -} - -int mitk::Mesh::SearchFirstCell(unsigned long pointId, int t) -{ - // iterate through all cells and find the cell the given pointId is inside - ConstCellIterator it = m_PointSetSeries[t]->GetCells()->Begin(); - ConstCellIterator end = m_PointSetSeries[t]->GetCells()->End(); - while (it != end) - { - PointIdIterator position = std::find(it->Value()->PointIdsBegin(), it->Value()->PointIdsEnd(), pointId); - - if (position != it->Value()->PointIdsEnd()) - { - return it->Index(); - } - ++it; - } - return -1; -} - -// Due to not implemented itk::CellInterface::EvaluatePosition and errors in -// using vtkCell::EvaluatePosition (changing iterator!) we must implement -// it in mitk::Mesh -// make it easy and look for hit points and hit lines: needs to be done anyway! -bool mitk::Mesh::EvaluatePosition(mitk::Point3D point, unsigned long &cellId, float precision, int t) -{ - int pointId = this->SearchPoint(point, precision, t); - if (pointId > -1) - { - // search the cell the point lies inside - cellId = this->SearchFirstCell(pointId, t); - return true; - } - unsigned long lineId = 0; - if (this->SearchLine(point, precision, lineId, cellId, t)) - { - return true; - } - - return false; -} - -unsigned long mitk::Mesh::GetNewCellId(int t) -{ - long nextCellId = -1; - ConstCellIterator it = m_PointSetSeries[t]->GetCells()->Begin(); - ConstCellIterator end = m_PointSetSeries[t]->GetCells()->End(); - - while (it != end) - { - nextCellId = it.Index(); - ++it; - } - ++nextCellId; - return nextCellId; -} - -int mitk::Mesh::SearchSelectedCell(int t) -{ - CellDataIterator cellDataIt, cellDataEnd; - cellDataEnd = m_PointSetSeries[t]->GetCellData()->End(); - for (cellDataIt = m_PointSetSeries[t]->GetCellData()->Begin(); cellDataIt != cellDataEnd; cellDataIt++) - { - // then declare an operation which unselects this line; UndoOperation as well! - if (cellDataIt->Value().selected) - { - return cellDataIt->Index(); - } - } - return -1; -} - -// get the cell; then iterate through the Ids times lineId. Then IdA ist the -// one, IdB ist ne next.don't forget the last closing line if the cell is -// closed -bool mitk::Mesh::GetPointIds(unsigned long cellId, unsigned long lineId, int &idA, int &idB, int t) -{ - CellAutoPointer cellAutoPointer; - bool ok = m_PointSetSeries[t]->GetCell(cellId, cellAutoPointer); - if (ok) - { - CellType *cell = cellAutoPointer.GetPointer(); - - // Get the cellData to also check the closing line - CellDataType cellData; - m_PointSetSeries[t]->GetCellData(cellId, &cellData); - bool closed = cellData.closed; - - PointIdIterator pointIdIt = cell->PointIdsBegin(); - PointIdIterator pointIdEnd = cell->PointIdsEnd(); - unsigned int counter = 0; - bool found = false; - while (pointIdIt != pointIdEnd) - { - if (counter == lineId) - { - idA = (*pointIdIt); - ++pointIdIt; - found = true; - break; - } - ++counter; - ++pointIdIt; - } - if (found) - { - // if in the middle - if (pointIdIt != pointIdEnd) - { - idB = (*pointIdIt); - } - // if found but on the end, then it is the closing connection, so the - // last and the first point - else if (closed) - { - pointIdIt = cell->PointIdsBegin(); - idB = (*pointIdIt); - } - } - else - ok = false; - } - return ok; -} - -void mitk::Mesh::ExecuteOperation(Operation *operation) -{ - // adding only the operations, that aren't implemented by the pointset. - switch (operation->GetOperationType()) - { - case OpNOTHING: - break; - - case OpNEWCELL: - { - auto *lineOp = dynamic_cast<mitk::LineOperation *>(operation); - - // if no lineoperation, then call superclass pointSet - if (lineOp == nullptr) - { - Superclass::ExecuteOperation(operation); - } - - bool ok; - int cellId = lineOp->GetCellId(); - CellAutoPointer cellAutoPointer; - ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer); - - // if it doesn't already exist - if (!ok) - { - cellAutoPointer.TakeOwnership(new PolygonType); - m_PointSetSeries[0]->SetCell(cellId, cellAutoPointer); - CellDataType cellData; - cellData.selected = true; - cellData.selectedLines.clear(); - cellData.closed = false; - m_PointSetSeries[0]->SetCellData(cellId, cellData); - } - } - break; - - case OpDELETECELL: - { - auto *lineOp = dynamic_cast<mitk::LineOperation *>(operation); - if (lineOp == nullptr) // if no lineoperation, then call superclass pointSet - { - Superclass::ExecuteOperation(operation); - } - m_PointSetSeries[0]->GetCells()->DeleteIndex((unsigned)lineOp->GetCellId()); - m_PointSetSeries[0]->GetCellData()->DeleteIndex((unsigned)lineOp->GetCellId()); - } - break; - - case OpCLOSECELL: - // sets the bolean flag closed from a specified cell to true. - { - auto *lineOp = dynamic_cast<mitk::LineOperation *>(operation); - if (lineOp == nullptr) // if no lineoperation, then call superclass pointSet - { - // then search the selected cell!//TODO - Superclass::ExecuteOperation(operation); - } - bool ok; - int cellId = lineOp->GetCellId(); - if (cellId < 0) // cellId isn't set - { - cellId = this->SearchSelectedCell(0); - if (cellId < 0) // still not found - return; - } - CellAutoPointer cellAutoPointer; - - // get directly the celldata!TODO - ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer); - if (ok) - { - CellDataType cellData; - m_PointSetSeries[0]->GetCellData(cellId, &cellData); - cellData.closed = true; - m_PointSetSeries[0]->SetCellData(cellId, cellData); - } - } - break; - - case OpOPENCELL: - { - auto *lineOp = dynamic_cast<mitk::LineOperation *>(operation); - if (lineOp == nullptr) // if no lineoperation, then call superclass pointSet - { - Superclass::ExecuteOperation(operation); - } - bool ok; - int cellId = lineOp->GetCellId(); - CellAutoPointer cellAutoPointer; - ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer); - if (ok) - { - CellDataType cellData; - m_PointSetSeries[0]->GetCellData(cellId, &cellData); - cellData.closed = false; - ; - m_PointSetSeries[0]->SetCellData(cellId, cellData); - } - } - break; - - case OpADDLINE: - // inserts the ID of the selected point into the indexes of lines in the - // selected cell afterwars the added line is selected - { - auto *lineOp = dynamic_cast<mitk::LineOperation *>(operation); - - int cellId = -1; - int pId = -1; - - if (lineOp == nullptr) - { - cellId = this->SearchSelectedCell(0); - if (cellId == -1) - return; - - pId = this->SearchSelectedPoint(0); - if (pId == -1) - return; - } - else - { - cellId = lineOp->GetCellId(); - if (cellId == -1) - return; - pId = lineOp->GetPIdA(); - if (pId == -1) - return; - } - - bool ok; - CellAutoPointer cellAutoPointer; - ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer); - if (ok) - { - CellType *cell = cellAutoPointer.GetPointer(); - if (cell->GetType() == CellType::POLYGON_CELL) - { - auto *polygon = static_cast<PolygonType *>(cell); - // add the pointId to the Cell. filling the empty cell with - // one id doesn't mean to add a line, it means, that the - // initilal PointId is set. The next addition of a pointId adds - // a line - polygon->AddPointId(pId); - - // select the line, if we really added a line, so now have more than - // 1 pointID in the cell - CellDataType cellData; - ok = m_PointSetSeries[0]->GetCellData(cellId, &cellData); - if (ok) - { - // A line between point 0 and 1 has the Id 0. A line between - // 1 and 2 has a Id = 1. So we add getnumberofpoints-2. - if (polygon->GetNumberOfPoints() > 1) - cellData.selectedLines.push_back(polygon->GetNumberOfPoints() - 2); - } - m_PointSetSeries[0]->SetCellData(cellId, cellData); - m_PointSetSeries[0]->SetCell(cellId, cellAutoPointer); - } - } - } - break; - - case OpDELETELINE: - { - // deleted the last line through removing the index PIdA - // (if set to -1, use the last point) in the given cellId - auto *lineOp = dynamic_cast<mitk::LineOperation *>(operation); - int cellId = -1; - int pId = -1; - - if (lineOp == nullptr) - { - cellId = this->SearchSelectedCell(0); - if (cellId == -1) - return; - pId = this->SearchSelectedPoint(0); - } - else - { - cellId = lineOp->GetCellId(); - if (cellId == -1) - return; - pId = lineOp->GetPIdA(); - } - - bool ok; - CellAutoPointer cellAutoPointer; - ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer); - if (ok) - { - CellType *cell = cellAutoPointer.GetPointer(); - if (cell->GetType() == CellType::POLYGON_CELL) - { - auto *oldPolygon = static_cast<PolygonType *>(cell); - - auto newPolygonCell = new PolygonType; - CellAutoPointer newCell; - newCell.TakeOwnership(newPolygonCell); - - PointIdConstIterator it, oldend; - oldend = oldPolygon->PointIdsEnd(); - if (pId >= 0) - { - for (it = oldPolygon->PointIdsBegin(); it != oldend; ++it) - { - if ((*it) != (MeshType::PointIdentifier)pId) - { - newPolygonCell->AddPointId(*it); - } - } - } - else - { - --oldend; - for (it = oldPolygon->PointIdsBegin(); it != oldend; ++it) - newPolygonCell->AddPointId(*it); - } - oldPolygon->SetPointIds(0, newPolygonCell->GetNumberOfPoints(), newPolygonCell->PointIdsBegin()); - } - } - } - break; - - case OpREMOVELINE: - // Remove the given Index in the given cell through copying everything - // into a new cell accept the one that has to be deleted. - { - auto *lineOp = dynamic_cast<mitk::LineOperation *>(operation); - if (lineOp == nullptr) // if no lineoperation, then call superclass pointSet - { - Superclass::ExecuteOperation(operation); - } - - bool ok; - CellAutoPointer cellAutoPointer; - int cellId = lineOp->GetCellId(); - ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer); - if (!ok) - return; - - CellType *cell = cellAutoPointer.GetPointer(); - CellAutoPointer newCellAutoPointer; - newCellAutoPointer.TakeOwnership(new PolygonType); - auto *newPolygon = static_cast<PolygonType *>(cell); - - PointIdIterator it = cell->PointIdsBegin(); - PointIdIterator end = cell->PointIdsEnd(); - int pointId = lineOp->GetPIdA(); - if (pointId < 0) // if not initialized!! - return; - - while (it != end) - { - if ((*it) == (unsigned int)pointId) - { - break; - } - else - { - newPolygon->AddPointId(*it); - } - ++it; - } - while (it != end) - { - newPolygon->AddPointId(*it); - it++; - } - m_PointSetSeries[0]->SetCell(cellId, newCellAutoPointer); - } - break; - - case OpINSERTLINE: - // //insert line between two other points. - ////before A--B after A--C--B - // //the points A, B and C have to be in the pointset. - // //needed: CellId, Id of C , Id A and Id B - ////the cell has to exist! - //{ - // mitk::LineOperation *lineOp = dynamic_cast<mitk::LineOperation *>(operation); - // if (lineOp == nullptr)//if no lineoperation, then call superclass pointSet - // { - // Superclass::ExecuteOperation(operation); - // } - // int cellId = lineOp->GetCellId(); - // int pIdC = lineOp->GetPIdC(); - // int pIdA = lineOp->GetPIdA(); - // int pIdB = lineOp->GetPIdB(); - - // //the points of the given PointIds have to exist in the PointSet - // bool ok; - // ok = m_PointSetSeries[0]->GetPoints()->IndexExists(pIdA); - // if (!ok) - // return; - // ok = m_PointSetSeries[0]->GetPoints()->IndexExists(pIdB); - // if (!ok) - // return; - // ok = m_PointSetSeries[0]->GetPoints()->IndexExists(pIdC); - // if (!ok) - // return; - - // // so the points do exist. So now check, if there is already a cell - // // with the given Id - // DataType::CellAutoPointer cell; - // ok = m_PointSetSeries[0]->GetCell(cellId, cell); - // if (!ok) - // return; - - // //pIdA and pIdB should exist in the cell - // - // PointIdIterator pit = cell->PointIdsBegin(); - // PointIdIterator end = cell->PointIdsEnd(); - // - // //now arrange the new Ids in the cell like desired; pIdC between - // // pIdA and pIdB - // unsigned int nuPoints = cell->GetNumberOfPoints(); - - // std::vector<unsigned int> newPoints; - // pit = cell->PointIdsBegin(); - // end = cell->PointIdsEnd(); - // int i = 0; - // while( pit != end ) - // { - // if ((*pit) = pIdA) - // { - // //now we have found the place to add pIdC after - // newPoints[i] = (*pit); - // i++; - // newPoints[i] = pIdC; - // } - // else - // newPoints[i] = (*pit); - // pit++; - // } - - // //now we have the Ids, that existed before combined with the new ones - // //so delete the old cell - // //doesn't seem to be necessary! - // //cell->ClearPoints(); - // pit = cell->PointIdsBegin(); - // cell->SetPointIds(pit); - //} - break; - - case OpMOVELINE: //(moves two points) - { - auto *lineOp = dynamic_cast<mitk::LineOperation *>(operation); - - if (lineOp == nullptr) - { - mitk::StatusBar::GetInstance()->DisplayText( - "Message from mitkMesh: Recieved wrong type of operation! See mitkMeshInteractor.cpp", 10000); - return; - } - - // create two operations out of the one operation and call superclass - // through the transmitted pointIds get the koordinates of the points. - // then add the transmitted vestor to them - // create two operations and send them to superclass - Point3D pointA, pointB; - pointA.Fill(0.0); - pointB.Fill(0.0); - m_PointSetSeries[0]->GetPoint(lineOp->GetPIdA(), &pointA); - m_PointSetSeries[0]->GetPoint(lineOp->GetPIdB(), &pointB); - - pointA[0] += lineOp->GetVector()[0]; - pointA[1] += lineOp->GetVector()[1]; - pointA[2] += lineOp->GetVector()[2]; - pointB[0] += lineOp->GetVector()[0]; - pointB[1] += lineOp->GetVector()[1]; - pointB[2] += lineOp->GetVector()[2]; - - auto operationA = new mitk::PointOperation(OpMOVE, pointA, lineOp->GetPIdA()); - auto operationB = new mitk::PointOperation(OpMOVE, pointB, lineOp->GetPIdB()); - - Superclass::ExecuteOperation(operationA); - Superclass::ExecuteOperation(operationB); - } - break; - - case OpSELECTLINE: //(select the given line) - { - auto *lineOp = dynamic_cast<mitk::LineOperation *>(operation); - if (lineOp == nullptr) // if no lineoperation, then call superclass pointSet - { - Superclass::ExecuteOperation(operation); - } - int cellId = lineOp->GetCellId(); - CellAutoPointer cellAutoPointer; - bool ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer); - if (ok) - { - CellDataType cellData; - m_PointSetSeries[0]->GetCellData(cellId, &cellData); - SelectedLinesType *selectedLines = &(cellData.selectedLines); - auto position = std::find(selectedLines->begin(), selectedLines->end(), (unsigned int)lineOp->GetId()); - - if (position == selectedLines->end()) // if not alsready selected - { - cellData.selectedLines.push_back(lineOp->GetId()); - } - m_PointSetSeries[0]->SetCellData(lineOp->GetCellId(), cellData); - } - } - break; - - case OpDESELECTLINE: //(deselect the given line) - { - auto *lineOp = dynamic_cast<mitk::LineOperation *>(operation); - if (lineOp == nullptr) - { - Superclass::ExecuteOperation(operation); - } - int cellId = lineOp->GetCellId(); - CellAutoPointer cellAutoPointer; - bool ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer); - if (ok) - { - CellDataType cellData; - m_PointSetSeries[0]->GetCellData(cellId, &cellData); - SelectedLinesType *selectedLines = &(cellData.selectedLines); - auto position = std::find(selectedLines->begin(), selectedLines->end(), (unsigned int)lineOp->GetId()); - - if (position != selectedLines->end()) // if found - { - selectedLines->erase(position); - } - m_PointSetSeries[0]->SetCellData(cellId, cellData); - } - } - break; - - case OpSELECTCELL: //(select the given cell) - { - auto *lineOp = dynamic_cast<mitk::LineOperation *>(operation); - if (lineOp == nullptr) // if no lineoperation, then call superclass pointSet - { - Superclass::ExecuteOperation(operation); - } - - int cellId = lineOp->GetCellId(); - CellAutoPointer cellAutoPointer; - - // directly get the data!//TODO - bool ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer); - if (ok) - { - CellDataType cellData; - m_PointSetSeries[0]->GetCellData(cellId, &cellData); - cellData.selected = true; - m_PointSetSeries[0]->SetCellData(cellId, cellData); - } - } - break; - - case OpDESELECTCELL: //(deselect the given cell) - { - auto *lineOp = dynamic_cast<mitk::LineOperation *>(operation); - if (lineOp == nullptr) // if no lineoperation, then call superclass pointSet - { - Superclass::ExecuteOperation(operation); - } - int cellId = lineOp->GetCellId(); - CellAutoPointer cellAutoPointer; - bool ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer); - if (ok) - { - CellDataType cellData; - m_PointSetSeries[0]->GetCellData(cellId, &cellData); - cellData.selected = false; - m_PointSetSeries[0]->SetCellData(cellId, cellData); - } - } - break; - - case OpMOVECELL: - // moves all Points of one cell according to the given vector - { - auto *lineOp = dynamic_cast<mitk::CellOperation *>(operation); - if (lineOp == nullptr) // if no celloperation, then call superclass pointSet - { - Superclass::ExecuteOperation(operation); - } - - int cellId = lineOp->GetCellId(); - Vector3D vector = lineOp->GetVector(); - - // get the cell - CellAutoPointer cellAutoPointer; - bool ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer); - if (!ok) - return; - - CellDataType cellData; - m_PointSetSeries[0]->GetCellData(cellId, &cellData); - // iterate through the pointIds of the CellData and move those points in - // the pointset - PointIdIterator it = cellAutoPointer->PointIdsBegin(); - PointIdIterator end = cellAutoPointer->PointIdsEnd(); - while (it != end) - { - unsigned int position = (*it); - PointType point; - point.Fill(0); - m_PointSetSeries[0]->GetPoint(position, &point); - point = point + vector; - m_PointSetSeries[0]->SetPoint(position, point); - ++it; - } - } - break; - - default: - // if the operation couldn't be handled here, then send it to superclass - Superclass::ExecuteOperation(operation); - return; - } - // to tell the mappers, that the data is modifierd and has to be updated - this->Modified(); - - mitk::OperationEndEvent endevent(operation); - ((const itk::Object *)this)->InvokeEvent(endevent); - - // As discussed lately, don't mess with rendering from inside data structures - //*todo has to be done here, cause of update-pipeline not working yet - // mitk::RenderingManager::GetInstance()->RequestUpdateAll(); -} - -mitk::Mesh::DataType::BoundingBoxPointer mitk::Mesh::GetBoundingBoxFromCell(unsigned long cellId, int t) -{ - // itk::CellInterface has also a GetBoundingBox, but it - // returns CoordRepType [PointDimension *2] - DataType::BoundingBoxPointer bBoxPointer = nullptr; - CellAutoPointer cellAutoPointer; - if (m_PointSetSeries[t]->GetCell(cellId, cellAutoPointer)) - { - DataType::PointsContainerPointer pointsContainer = DataType::PointsContainer::New(); - PointIdIterator bbIt = cellAutoPointer.GetPointer()->PointIdsBegin(); - PointIdIterator bbEnd = cellAutoPointer.GetPointer()->PointIdsEnd(); - while (bbIt != bbEnd) - { - mitk::PointSet::PointType point; - bool pointOk = m_PointSetSeries[t]->GetPoint((*bbIt), &point); - if (pointOk) - pointsContainer->SetElement((*bbIt), point); - ++bbIt; - } - bBoxPointer = DataType::BoundingBoxType::New(); - bBoxPointer->SetPoints(pointsContainer); - bBoxPointer->ComputeBoundingBox(); - } - return bBoxPointer; -} diff --git a/Modules/DataTypesExt/test/files.cmake b/Modules/DataTypesExt/test/files.cmake index 048ece655e..356091d282 100644 --- a/Modules/DataTypesExt/test/files.cmake +++ b/Modules/DataTypesExt/test/files.cmake @@ -1,18 +1,17 @@ set(MODULE_TESTS mitkColorSequenceRainbowTest.cpp - mitkMeshTest.cpp mitkMultiStepperTest.cpp mitkUnstructuredGridTest.cpp ) set(MODULE_IMAGE_TESTS mitkCompressedImageContainerTest.cpp #only runs on images ) set(MODULE_TESTIMAGE US4DCyl.nrrd Pic3D.nrrd Pic2DplusT.nrrd BallBinary30x30x30.nrrd Png2D-bw.png ) diff --git a/Modules/DataTypesExt/test/mitkMeshTest.cpp b/Modules/DataTypesExt/test/mitkMeshTest.cpp deleted file mode 100644 index aa6dd719a9..0000000000 --- a/Modules/DataTypesExt/test/mitkMeshTest.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/*============================================================================ - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center (DKFZ) -All rights reserved. - -Use of this source code is governed by a 3-clause BSD license that can be -found in the LICENSE file. - -============================================================================*/ - -#include <fstream> -#include <mitkInteractionConst.h> -#include <mitkMesh.h> -#include <mitkNumericTypes.h> -#include <mitkPointOperation.h> - -int mitkMeshTest(int /*argc*/, char * /*argv*/ []) -{ - // Create mesh - mitk::Mesh::Pointer mesh; - mesh = mitk::Mesh::New(); - - // try to get the itkmesh - std::cout << "Create a mesh and try to get the itkMesh"; - mitk::Mesh::DataType::Pointer itkdata = nullptr; - itkdata = mesh->GetMesh(); - if (itkdata.IsNull()) - { - std::cout << "[FAILED]" << std::endl; - return EXIT_FAILURE; - } - - // fresh mesh has to be empty! - std::cout << "Is the mesh empty?"; - if (mesh->GetSize() != 0) - { - std::cout << "[FAILED]" << std::endl; - return EXIT_FAILURE; - } - - // create an operation and add a point. - int position = 0; - mitk::Point3D point; - point.Fill(1); - auto doOp = new mitk::PointOperation(mitk::OpINSERT, point, position); - mesh->ExecuteOperation(doOp); - - // now check new condition! - if ((mesh->GetSize() != 1) || (!mesh->IndexExists(position))) - { - std::cout << "[FAILED]" << std::endl; - return EXIT_FAILURE; - } - delete doOp; - - // get the point and check if it is still the same - std::cout << "Create an operation and add a point. Then try to get that point."; - mitk::Point3D tempPoint; - tempPoint.Fill(0); - tempPoint = mesh->GetPoint(position); - if (tempPoint != point) - { - std::cout << "[FAILED]" << std::endl; - return EXIT_FAILURE; - } - - // well done!!! Passed! - std::cout << "[PASSED]" << std::endl; - - std::cout << "[TEST DONE]" << std::endl; - return EXIT_SUCCESS; -} diff --git a/Modules/IOExt/Internal/mitkIOExtObjectFactory.cpp b/Modules/IOExt/Internal/mitkIOExtObjectFactory.cpp index d268917ff6..86ca564d52 100644 --- a/Modules/IOExt/Internal/mitkIOExtObjectFactory.cpp +++ b/Modules/IOExt/Internal/mitkIOExtObjectFactory.cpp @@ -1,180 +1,167 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "mitkIOExtObjectFactory.h" #include "mitkCoreObjectFactory.h" #include "mitkParRecFileIOFactory.h" //#include "mitkObjFileIOFactory.h" #include "mitkStlVolumeTimeSeriesIOFactory.h" #include "mitkVtkVolumeTimeSeriesIOFactory.h" #include "mitkUnstructuredGridVtkWriter.h" #include "mitkUnstructuredGridVtkWriterFactory.h" #include "mitkVolumeMapperVtkSmart3D.h" -#include "mitkMesh.h" -#include "mitkMeshMapper2D.h" -#include "mitkMeshVtkMapper3D.h" #include "mitkUnstructuredGridMapper2D.h" #include "mitkUnstructuredGridVtkMapper3D.h" #include "mitkVtkGLMapperWrapper.h" #include <vtkUnstructuredGridWriter.h> #include <vtkXMLPUnstructuredGridWriter.h> #include <vtkXMLUnstructuredGridWriter.h> mitk::IOExtObjectFactory::IOExtObjectFactory() : CoreObjectFactoryBase(), m_ParRecFileIOFactory(ParRecFileIOFactory::New().GetPointer()) //, m_ObjFileIOFactory(ObjFileIOFactory::New().GetPointer()) , m_StlVolumeTimeSeriesIOFactory(StlVolumeTimeSeriesIOFactory::New().GetPointer()), m_VtkVolumeTimeSeriesIOFactory(VtkVolumeTimeSeriesIOFactory::New().GetPointer()), m_UnstructuredGridVtkWriterFactory(UnstructuredGridVtkWriterFactory::New().GetPointer()) { static bool alreadyDone = false; if (!alreadyDone) { MITK_DEBUG << "IOExtObjectFactory c'tor" << std::endl; itk::ObjectFactoryBase::RegisterFactory(m_ParRecFileIOFactory); itk::ObjectFactoryBase::RegisterFactory(m_StlVolumeTimeSeriesIOFactory); itk::ObjectFactoryBase::RegisterFactory(m_VtkVolumeTimeSeriesIOFactory); itk::ObjectFactoryBase::RegisterFactory(m_UnstructuredGridVtkWriterFactory); m_FileWriters.push_back(mitk::UnstructuredGridVtkWriter<vtkUnstructuredGridWriter>::New().GetPointer()); m_FileWriters.push_back(mitk::UnstructuredGridVtkWriter<vtkXMLUnstructuredGridWriter>::New().GetPointer()); m_FileWriters.push_back(mitk::UnstructuredGridVtkWriter<vtkXMLPUnstructuredGridWriter>::New().GetPointer()); CreateFileExtensionsMap(); alreadyDone = true; } } mitk::IOExtObjectFactory::~IOExtObjectFactory() { itk::ObjectFactoryBase::UnRegisterFactory(m_ParRecFileIOFactory); itk::ObjectFactoryBase::UnRegisterFactory(m_StlVolumeTimeSeriesIOFactory); itk::ObjectFactoryBase::UnRegisterFactory(m_VtkVolumeTimeSeriesIOFactory); itk::ObjectFactoryBase::UnRegisterFactory(m_UnstructuredGridVtkWriterFactory); } mitk::Mapper::Pointer mitk::IOExtObjectFactory::CreateMapper(mitk::DataNode *node, MapperSlotId id) { mitk::Mapper::Pointer newMapper = nullptr; mitk::BaseData *data = node->GetData(); if (id == mitk::BaseRenderer::Standard2D) { - if ((dynamic_cast<Mesh *>(data) != nullptr)) - { - newMapper = mitk::MeshMapper2D::New(); - newMapper->SetDataNode(node); - } - else if ((dynamic_cast<UnstructuredGrid *>(data) != nullptr)) + if ((dynamic_cast<UnstructuredGrid *>(data) != nullptr)) { newMapper = mitk::VtkGLMapperWrapper::New(mitk::UnstructuredGridMapper2D::New().GetPointer()); newMapper->SetDataNode(node); } } else if (id == mitk::BaseRenderer::Standard3D) { if ((dynamic_cast<Image *>(data) != nullptr) && std::string("Image").compare(node->GetData()->GetNameOfClass())==0) { newMapper = mitk::VolumeMapperVtkSmart3D::New(); newMapper->SetDataNode(node); } - else if ((dynamic_cast<Mesh *>(data) != nullptr)) - { - newMapper = mitk::MeshVtkMapper3D::New(); - newMapper->SetDataNode(node); - } else if ((dynamic_cast<UnstructuredGrid *>(data) != nullptr)) { newMapper = mitk::UnstructuredGridVtkMapper3D::New(); newMapper->SetDataNode(node); } } return newMapper; } void mitk::IOExtObjectFactory::SetDefaultProperties(mitk::DataNode *node) { if (node == nullptr) return; mitk::DataNode::Pointer nodePointer = node; mitk::Image::Pointer image = dynamic_cast<mitk::Image *>(node->GetData()); if (image.IsNotNull() && image->IsInitialized()) { mitk::VolumeMapperVtkSmart3D::SetDefaultProperties(node); } if (dynamic_cast<mitk::UnstructuredGrid *>(node->GetData())) { mitk::UnstructuredGridVtkMapper3D::SetDefaultProperties(node); } } std::string mitk::IOExtObjectFactory::GetFileExtensions() { std::string fileExtension; this->CreateFileExtensions(m_FileExtensionsMap, fileExtension); return fileExtension.c_str(); } mitk::CoreObjectFactoryBase::MultimapType mitk::IOExtObjectFactory::GetFileExtensionsMap() { return m_FileExtensionsMap; } mitk::CoreObjectFactoryBase::MultimapType mitk::IOExtObjectFactory::GetSaveFileExtensionsMap() { return m_SaveFileExtensionsMap; } void mitk::IOExtObjectFactory::CreateFileExtensionsMap() { m_FileExtensionsMap.insert(std::pair<std::string, std::string>("*.vtu", "VTK Unstructured Grid")); m_FileExtensionsMap.insert(std::pair<std::string, std::string>("*.vtk", "VTK Unstructured Grid")); m_FileExtensionsMap.insert(std::pair<std::string, std::string>("*.pvtu", "VTK Unstructured Grid")); m_SaveFileExtensionsMap.insert(std::pair<std::string, std::string>("*.pvtu", "VTK Parallel XML Unstructured Grid")); m_SaveFileExtensionsMap.insert(std::pair<std::string, std::string>("*.vtu", "VTK XML Unstructured Grid")); m_SaveFileExtensionsMap.insert(std::pair<std::string, std::string>("*.vtk", "VTK Legacy Unstructured Grid")); } std::string mitk::IOExtObjectFactory::GetSaveFileExtensions() { std::string fileExtension; this->CreateFileExtensions(m_SaveFileExtensionsMap, fileExtension); return fileExtension.c_str(); } struct RegisterIOExtObjectFactory { RegisterIOExtObjectFactory() : m_Factory(mitk::IOExtObjectFactory::New()) { mitk::CoreObjectFactory::GetInstance()->RegisterExtraFactory(m_Factory); } ~RegisterIOExtObjectFactory() { mitk::CoreObjectFactory::GetInstance()->UnRegisterExtraFactory(m_Factory); } mitk::IOExtObjectFactory::Pointer m_Factory; }; static RegisterIOExtObjectFactory registerIOExtObjectFactory; diff --git a/Modules/MapperExt/files.cmake b/Modules/MapperExt/files.cmake index 3ec5ef80f6..01778f6a7a 100644 --- a/Modules/MapperExt/files.cmake +++ b/Modules/MapperExt/files.cmake @@ -1,20 +1,18 @@ file(GLOB_RECURSE H_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/include/*") set(CPP_FILES mitkEnhancedPointSetVtkMapper3D.cpp mitkGPUVolumeMapper3D.cpp - mitkMeshMapper2D.cpp - mitkMeshVtkMapper3D.cpp mitkSplineVtkMapper3D.cpp mitkUnstructuredGridMapper2D.cpp mitkUnstructuredGridVtkMapper3D.cpp mitkVectorImageMapper2D.cpp mitkVolumeMapperVtkSmart3D.cpp vtkMaskedGlyph2D.cpp vtkMaskedGlyph3D.cpp vtkMitkGPUVolumeRayCastMapper.cpp vtkUnstructuredGridMapper.cpp vtkPointSetSlicer.cxx ) diff --git a/Modules/MapperExt/include/mitkMeshMapper2D.h b/Modules/MapperExt/include/mitkMeshMapper2D.h deleted file mode 100644 index 30926d3089..0000000000 --- a/Modules/MapperExt/include/mitkMeshMapper2D.h +++ /dev/null @@ -1,53 +0,0 @@ -/*============================================================================ - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center (DKFZ) -All rights reserved. - -Use of this source code is governed by a 3-clause BSD license that can be -found in the LICENSE file. - -============================================================================*/ - -#ifndef MITKMESHMAPPER2D_H_HEADER_INCLUDED -#define MITKMESHMAPPER2D_H_HEADER_INCLUDED - -#include "MitkMapperExtExports.h" -#include "mitkCommon.h" -#include "mitkGLMapper.h" - -namespace mitk -{ - class BaseRenderer; - class Mesh; - - /** - * \brief OpenGL-based mapper to display a mesh in a 2D window - * - * \todo implement for AbstractTransformGeometry. - * \ingroup Mapper - */ - class MITKMAPPEREXT_EXPORT MeshMapper2D : public GLMapper - { - public: - mitkClassMacro(MeshMapper2D, GLMapper); - - itkFactorylessNewMacro(Self); - - itkCloneMacro(Self); - - /** @brief Get the Mesh to map */ - const mitk::Mesh *GetInput(void); - - void Paint(mitk::BaseRenderer *renderer) override; - - protected: - MeshMapper2D(); - - ~MeshMapper2D() override; - }; - -} // namespace mitk - -#endif /* MITKMESHMapper2D_H_HEADER_INCLUDED */ diff --git a/Modules/MapperExt/include/mitkMeshVtkMapper3D.h b/Modules/MapperExt/include/mitkMeshVtkMapper3D.h deleted file mode 100644 index 59391e03f4..0000000000 --- a/Modules/MapperExt/include/mitkMeshVtkMapper3D.h +++ /dev/null @@ -1,87 +0,0 @@ -/*============================================================================ - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center (DKFZ) -All rights reserved. - -Use of this source code is governed by a 3-clause BSD license that can be -found in the LICENSE file. - -============================================================================*/ - -#ifndef MITKMESHVTKMAPPER3D_H_HEADER_INCLUDED -#define MITKMESHVTKMAPPER3D_H_HEADER_INCLUDED - -#include "MitkMapperExtExports.h" -#include "mitkBaseRenderer.h" -#include "mitkCommon.h" -#include "mitkMesh.h" -#include "mitkVtkMapper.h" - -#include <vtkAppendPolyData.h> -#include <vtkCellArray.h> -#include <vtkFloatArray.h> -#include <vtkLinearTransform.h> -#include <vtkPointData.h> -#include <vtkPoints.h> -#include <vtkPolyData.h> -#include <vtkSphereSource.h> -#include <vtkTextSource.h> -#include <vtkTransformPolyDataFilter.h> -#include <vtkTubeFilter.h> -#include <vtkVectorText.h> - -class vtkActor; -class vtkAssembly; -class vtkFollower; -class vtkPolyDataMapper; -class vtkPropAssembly; - -namespace mitk -{ - /** - * \brief Vtk-based mapper for PointList - * \ingroup Mapper - */ - class MITKMAPPEREXT_EXPORT MeshVtkMapper3D : public VtkMapper - { - public: - mitkClassMacro(MeshVtkMapper3D, VtkMapper); - - itkFactorylessNewMacro(Self); - - itkCloneMacro(Self); - - virtual const mitk::Mesh *GetInput(); - - vtkProp *GetVtkProp(mitk::BaseRenderer *renderer) override; - void UpdateVtkTransform(mitk::BaseRenderer *renderer) override; - - LocalStorageHandler<BaseLocalStorage> m_LSH; - - protected: - MeshVtkMapper3D(); - - ~MeshVtkMapper3D() override; - - void GenerateDataForRenderer(mitk::BaseRenderer *renderer) override; - - void ResetMapper(BaseRenderer *renderer) override; - - vtkPropAssembly *m_PropAssembly; - - vtkActor *m_SpheresActor; - vtkActor *m_ContourActor; - vtkPolyDataMapper *m_ContourMapper; - vtkPolyDataMapper *m_SpheresMapper; - - vtkPolyDataMapper *m_TextVtkPolyDataMapper; - - vtkAppendPolyData *m_Spheres; - vtkPolyData *m_Contour; - }; - -} // namespace mitk - -#endif /* MITKMESHVTKMAPPER3D_H_HEADER_INCLUDED*/ diff --git a/Modules/MapperExt/src/mitkMeshMapper2D.cpp b/Modules/MapperExt/src/mitkMeshMapper2D.cpp deleted file mode 100644 index c67bb42de6..0000000000 --- a/Modules/MapperExt/src/mitkMeshMapper2D.cpp +++ /dev/null @@ -1,472 +0,0 @@ -/*============================================================================ - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center (DKFZ) -All rights reserved. - -Use of this source code is governed by a 3-clause BSD license that can be -found in the LICENSE file. - -============================================================================*/ - -#include "mitkMeshMapper2D.h" -#include "mitkBaseRenderer.h" -#include "mitkColorProperty.h" -#include "mitkGL.h" -#include "mitkLine.h" -#include "mitkMesh.h" -#include "mitkPlaneGeometry.h" -#include "mitkProperties.h" - -#include <vtkLinearTransform.h> - -#include <algorithm> - -const float selectedColor[] = {1.0f, 0.0f, 0.6f}; // for selected! - -mitk::MeshMapper2D::MeshMapper2D() -{ -} - -mitk::MeshMapper2D::~MeshMapper2D() -{ -} - -const mitk::Mesh *mitk::MeshMapper2D::GetInput(void) -{ - return static_cast<const mitk::Mesh *>(GetDataNode()->GetData()); -} - -// Return whether a point is "smaller" than the second -static bool point3DSmaller(const mitk::Point3D &elem1, const mitk::Point3D &elem2) -{ - if (elem1[0] != elem2[0]) - return elem1[0] < elem2[0]; - if (elem1[1] != elem2[1]) - return elem1[1] < elem2[1]; - return elem1[2] < elem2[2]; -} - -void mitk::MeshMapper2D::Paint(mitk::BaseRenderer *renderer) -{ - bool visible = true; - - GetDataNode()->GetVisibility(visible, renderer, "visible"); - - if (!visible) - return; - - // @FIXME: Logik fuer update - bool updateNeccesary = true; - - if (updateNeccesary) - { - // aus GenerateData - mitk::Mesh::Pointer input = const_cast<mitk::Mesh *>(this->GetInput()); - - // Get the TimeGeometry of the input object - const TimeGeometry *inputTimeGeometry = input->GetTimeGeometry(); - if ((inputTimeGeometry == nullptr) || (inputTimeGeometry->CountTimeSteps() == 0)) - { - return; - } - - // - // get the world time - // - ScalarType time = renderer->GetTime(); - - // - // convert the world time in time steps of the input object - // - int timeStep = 0; - if (time > itk::NumericTraits<mitk::ScalarType>::NonpositiveMin()) - timeStep = inputTimeGeometry->TimePointToTimeStep(time); - if (inputTimeGeometry->IsValidTimeStep(timeStep) == false) - { - return; - } - - mitk::Mesh::MeshType::Pointer itkMesh = input->GetMesh(timeStep); - - if (itkMesh.GetPointer() == nullptr) - { - return; - } - - const PlaneGeometry *worldplanegeometry = (renderer->GetCurrentWorldPlaneGeometry()); - - // apply color and opacity read from the PropertyList - ApplyColorAndOpacityProperties(renderer); - - vtkLinearTransform *transform = GetDataNode()->GetVtkTransform(); - - // List of the Points - Mesh::DataType::PointsContainerConstIterator it, end; - it = itkMesh->GetPoints()->Begin(); - end = itkMesh->GetPoints()->End(); - - // iterator on the additional data of each point - Mesh::PointDataIterator dataIt; //, dataEnd; - dataIt = itkMesh->GetPointData()->Begin(); - - // for switching back to old color after using selected color - float unselectedColor[4]; - glGetFloatv(GL_CURRENT_COLOR, unselectedColor); - - while (it != end) - { - mitk::Point3D p, projected_p; - float vtkp[3]; - - itk2vtk(it->Value(), vtkp); - transform->TransformPoint(vtkp, vtkp); - vtk2itk(vtkp, p); - - renderer->GetCurrentWorldPlaneGeometry()->Project(p, projected_p); - Vector3D diff = p - projected_p; - if (diff.GetSquaredNorm() < 4.0) - { - Point2D pt2d, tmp; - renderer->WorldToDisplay(p, pt2d); - - Vector2D horz, vert; - horz[0] = 5; - horz[1] = 0; - vert[0] = 0; - vert[1] = 5; - - // check if the point is to be marked as selected - if (dataIt->Value().selected) - { - horz[0] = 8; - vert[1] = 8; - glColor3f(selectedColor[0], selectedColor[1], selectedColor[2]); // red - - switch (dataIt->Value().pointSpec) - { - case PTSTART: - // a quad - glBegin(GL_LINE_LOOP); - tmp = pt2d - horz + vert; - glVertex2dv(&tmp[0]); - tmp = pt2d + horz + vert; - glVertex2dv(&tmp[0]); - tmp = pt2d + horz - vert; - glVertex2dv(&tmp[0]); - tmp = pt2d - horz - vert; - glVertex2dv(&tmp[0]); - glEnd(); - break; - case PTUNDEFINED: - // a diamond around the point - glBegin(GL_LINE_LOOP); - tmp = pt2d - horz; - glVertex2dv(&tmp[0]); - tmp = pt2d + vert; - glVertex2dv(&tmp[0]); - tmp = pt2d + horz; - glVertex2dv(&tmp[0]); - tmp = pt2d - vert; - glVertex2dv(&tmp[0]); - glEnd(); - break; - default: - break; - } // switch - - // the actual point - glBegin(GL_POINTS); - tmp = pt2d; - glVertex2dv(&tmp[0]); - glEnd(); - } - else // if not selected - { - glColor3f(unselectedColor[0], unselectedColor[1], unselectedColor[2]); - switch (dataIt->Value().pointSpec) - { - case PTSTART: - // a quad - glBegin(GL_LINE_LOOP); - tmp = pt2d - horz + vert; - glVertex2dv(&tmp[0]); - tmp = pt2d + horz + vert; - glVertex2dv(&tmp[0]); - tmp = pt2d + horz - vert; - glVertex2dv(&tmp[0]); - tmp = pt2d - horz - vert; - glVertex2dv(&tmp[0]); - glEnd(); - break; - case PTUNDEFINED: - // drawing crosses - glBegin(GL_LINES); - tmp = pt2d - horz; - glVertex2dv(&tmp[0]); - tmp = pt2d + horz; - glVertex2dv(&tmp[0]); - tmp = pt2d - vert; - glVertex2dv(&tmp[0]); - tmp = pt2d + vert; - glVertex2dv(&tmp[0]); - glEnd(); - break; - default: - { - break; - } - } // switch - } // else - } - ++it; - ++dataIt; - } - - // now connect the lines inbetween - mitk::Mesh::PointType thisPoint; - thisPoint.Fill(0); - Point2D *firstOfCell = nullptr; - Point2D *lastPoint = nullptr; - unsigned int lastPointId = 0; - bool lineSelected = false; - - Point3D firstOfCell3D; - Point3D lastPoint3D; - bool first; - mitk::Line<mitk::ScalarType> line; - std::vector<mitk::Point3D> intersectionPoints; - double t; - - // iterate through all cells and then iterate through all indexes of points in that cell - Mesh::CellIterator cellIt, cellEnd; - Mesh::CellDataIterator cellDataIt; //, cellDataEnd; - Mesh::PointIdIterator cellIdIt, cellIdEnd; - - cellIt = itkMesh->GetCells()->Begin(); - cellEnd = itkMesh->GetCells()->End(); - cellDataIt = itkMesh->GetCellData()->Begin(); - - while (cellIt != cellEnd) - { - unsigned int numOfPointsInCell = cellIt->Value()->GetNumberOfPoints(); - if (numOfPointsInCell > 1) - { - // iterate through all id's in the cell - cellIdIt = cellIt->Value()->PointIdsBegin(); - cellIdEnd = cellIt->Value()->PointIdsEnd(); - - firstOfCell3D = input->GetPoint(*cellIdIt, timeStep); - - intersectionPoints.clear(); - intersectionPoints.reserve(numOfPointsInCell); - - first = true; - - while (cellIdIt != cellIdEnd) - { - lastPoint3D = thisPoint; - - thisPoint = input->GetPoint(*cellIdIt, timeStep); - - // search in data (vector<> selectedLines) if the index of the point is set. if so, then the line is selected. - lineSelected = false; - Mesh::SelectedLinesType selectedLines = cellDataIt->Value().selectedLines; - - // a line between 1(lastPoint) and 2(pt2d) has the Id 1, so look for the Id of lastPoint - // since we only start, if we have more than one point in the cell, lastPointId is initiated with 0 - auto position = std::find(selectedLines.begin(), selectedLines.end(), lastPointId); - if (position != selectedLines.end()) - { - lineSelected = true; - } - - mitk::Point3D p, projected_p; - float vtkp[3]; - itk2vtk(thisPoint, vtkp); - transform->TransformPoint(vtkp, vtkp); - vtk2itk(vtkp, p); - renderer->GetCurrentWorldPlaneGeometry()->Project(p, projected_p); - Vector3D diff = p - projected_p; - if (diff.GetSquaredNorm() < 4.0) - { - Point2D pt2d, tmp; - renderer->WorldToDisplay(p, pt2d); - - if (lastPoint == nullptr) - { - // set the first point in the cell. This point in needed to close the polygon - firstOfCell = new Point2D; - *firstOfCell = pt2d; - lastPoint = new Point2D; - *lastPoint = pt2d; - lastPointId = *cellIdIt; - } - else - { - if (lineSelected) - { - glColor3f(selectedColor[0], selectedColor[1], selectedColor[2]); // red - // a line from lastPoint to thisPoint - glBegin(GL_LINES); - glVertex2dv(&(*lastPoint)[0]); - glVertex2dv(&pt2d[0]); - glEnd(); - } - else // if not selected - { - glColor3f(unselectedColor[0], unselectedColor[1], unselectedColor[2]); - // drawing crosses - glBegin(GL_LINES); - glVertex2dv(&(*lastPoint)[0]); - glVertex2dv(&pt2d[0]); - glEnd(); - } - // to draw the line to the next in iteration step - *lastPoint = pt2d; - // and to search for the selection state of the line - lastPointId = *cellIdIt; - } // if..else - } // if <4.0 - - // fill off-plane polygon part 1 - if ((!first) && (worldplanegeometry != nullptr)) - { - line.SetPoints(lastPoint3D, thisPoint); - if (worldplanegeometry->IntersectionPointParam(line, t) && ((t >= 0) && (t <= 1))) - { - intersectionPoints.push_back(line.GetPoint(t)); - } - } - ++cellIdIt; - first = false; - } // while cellIdIter - - // closed polygon? - if (cellDataIt->Value().closed) - { - // close the polygon if needed - if (firstOfCell != nullptr) - { - lineSelected = false; - Mesh::SelectedLinesType selectedLines = cellDataIt->Value().selectedLines; - auto position = std::find(selectedLines.begin(), selectedLines.end(), lastPointId); - if (position != selectedLines.end()) // found the index - { - glColor3f(selectedColor[0], selectedColor[1], selectedColor[2]); // red - // a line from lastPoint to firstPoint - glBegin(GL_LINES); - glVertex2dv(&(*lastPoint)[0]); - glVertex2dv(&(*firstOfCell)[0]); - glEnd(); - } - else - { - glColor3f(unselectedColor[0], unselectedColor[1], unselectedColor[2]); - glBegin(GL_LINES); - glVertex2dv(&(*lastPoint)[0]); - glVertex2dv(&(*firstOfCell)[0]); - glEnd(); - } - } - } // if closed - - // Axis-aligned bounding box(AABB) around the cell if selected and set in Property - bool showBoundingBox; - if (dynamic_cast<mitk::BoolProperty *>(this->GetDataNode()->GetProperty("showBoundingBox")) == nullptr) - showBoundingBox = false; - else - showBoundingBox = - dynamic_cast<mitk::BoolProperty *>(this->GetDataNode()->GetProperty("showBoundingBox"))->GetValue(); - - if (showBoundingBox) - { - if (cellDataIt->Value().selected) - { - mitk::Mesh::DataType::BoundingBoxPointer aABB = input->GetBoundingBoxFromCell(cellIt->Index()); - if (aABB.IsNotNull()) - { - mitk::Mesh::PointType min, max; - min = aABB->GetMinimum(); - max = aABB->GetMaximum(); - - // project to the displayed geometry - Point2D min2D, max2D; - Point3D p, projected_p; - float vtkp[3]; - itk2vtk(min, vtkp); - transform->TransformPoint(vtkp, vtkp); - vtk2itk(vtkp, p); - renderer->WorldToDisplay(p, min2D); - - itk2vtk(max, vtkp); - transform->TransformPoint(vtkp, vtkp); - vtk2itk(vtkp, p); - renderer->GetCurrentWorldPlaneGeometry()->Project(p, projected_p); - Vector3D diff = p - projected_p; - if (diff.GetSquaredNorm() < 4.0) - { - renderer->WorldToDisplay(p, max2D); - - // draw the BoundingBox - glColor3f(selectedColor[0], selectedColor[1], selectedColor[2]); // red - // a line from lastPoint to firstPoint - glBegin(GL_LINE_LOOP); - glVertex2f(min2D[0], min2D[1]); - glVertex2f(min2D[0], max2D[1]); - glVertex2f(max2D[0], max2D[1]); - glVertex2f(max2D[0], min2D[1]); - glEnd(); - } // draw bounding-box - } // bounding-box exists - } // cell selected - } // show bounding-box - - // fill off-plane polygon part 2 - if (worldplanegeometry != nullptr) - { - // consider line from last to first - line.SetPoints(thisPoint, firstOfCell3D); - if (worldplanegeometry->IntersectionPointParam(line, t) && ((t >= 0) && (t <= 1))) - { - intersectionPoints.push_back(line.GetPoint(t)); - } - std::sort(intersectionPoints.begin(), intersectionPoints.end(), point3DSmaller); - std::vector<mitk::Point3D>::iterator it, end; - end = intersectionPoints.end(); - if ((intersectionPoints.size() % 2) != 0) - { - --end; // ensure even number of intersection-points - } - Point2D pt2d; - for (it = intersectionPoints.begin(); it != end; ++it) - { - glBegin(GL_LINES); - renderer->WorldToDisplay(*it, pt2d); - glVertex2dv(pt2d.GetDataPointer()); - ++it; - renderer->WorldToDisplay(*it, pt2d); - glVertex2dv(pt2d.GetDataPointer()); - glEnd(); - } - if (it != intersectionPoints.end()) - { - glBegin(GL_LINES); - renderer->WorldToDisplay(*it, pt2d); - glVertex2dv(pt2d.GetDataPointer()); - glVertex2dv(pt2d.GetDataPointer()); - glEnd(); - } - } // fill off-plane polygon part 2 - } // if numOfPointsInCell>1 - delete firstOfCell; - delete lastPoint; - lastPoint = nullptr; - firstOfCell = nullptr; - lastPointId = 0; - ++cellIt; - ++cellDataIt; - } - } -} diff --git a/Modules/MapperExt/src/mitkMeshVtkMapper3D.cpp b/Modules/MapperExt/src/mitkMeshVtkMapper3D.cpp deleted file mode 100644 index 1fca78d220..0000000000 --- a/Modules/MapperExt/src/mitkMeshVtkMapper3D.cpp +++ /dev/null @@ -1,226 +0,0 @@ -/*============================================================================ - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center (DKFZ) -All rights reserved. - -Use of this source code is governed by a 3-clause BSD license that can be -found in the LICENSE file. - -============================================================================*/ - -#include "mitkMeshVtkMapper3D.h" -#include "mitkDataNode.h" -#include "mitkProperties.h" -#include "mitkVtkPropRenderer.h" - -#ifndef VCL_VC60 -#include "mitkMeshUtil.h" -#endif - -#include <vtkActor.h> -#include <vtkAssembly.h> -#include <vtkFollower.h> -#include <vtkProp3DCollection.h> -#include <vtkPropAssembly.h> -#include <vtkRenderer.h> - -#include <cstdlib> -#include <vtkPolyDataMapper.h> -#include <vtkProperty.h> - -const mitk::Mesh *mitk::MeshVtkMapper3D::GetInput() -{ - return static_cast<const mitk::Mesh *>(GetDataNode()->GetData()); -} - -vtkProp *mitk::MeshVtkMapper3D::GetVtkProp(mitk::BaseRenderer * /*renderer*/) -{ - return m_PropAssembly; -} - -void mitk::MeshVtkMapper3D::UpdateVtkTransform(mitk::BaseRenderer * /*renderer*/) -{ - vtkLinearTransform *vtktransform = this->GetDataNode()->GetVtkTransform(this->GetTimestep()); - - m_SpheresActor->SetUserTransform(vtktransform); - m_ContourActor->SetUserTransform(vtktransform); -} - -mitk::MeshVtkMapper3D::MeshVtkMapper3D() : m_PropAssembly(nullptr) -{ - m_Spheres = vtkAppendPolyData::New(); - m_Contour = vtkPolyData::New(); - - m_SpheresActor = vtkActor::New(); - m_SpheresMapper = vtkPolyDataMapper::New(); - m_SpheresActor->SetMapper(m_SpheresMapper); - - m_ContourActor = vtkActor::New(); - m_ContourMapper = vtkPolyDataMapper::New(); - m_ContourActor->SetMapper(m_ContourMapper); - m_ContourActor->GetProperty()->SetAmbient(1.0); - - m_PropAssembly = vtkPropAssembly::New(); - - // a vtkPropAssembly is not a sub-class of vtkProp3D, so - // we cannot use m_Prop3D. -} - -mitk::MeshVtkMapper3D::~MeshVtkMapper3D() -{ - m_ContourActor->Delete(); - m_SpheresActor->Delete(); - m_ContourMapper->Delete(); - m_SpheresMapper->Delete(); - m_PropAssembly->Delete(); - m_Spheres->Delete(); - m_Contour->Delete(); -} - -void mitk::MeshVtkMapper3D::GenerateDataForRenderer(mitk::BaseRenderer *renderer) -{ - BaseLocalStorage *ls = m_LSH.GetLocalStorage(renderer); - bool needGenerateData = ls->IsGenerateDataRequired(renderer, this, GetDataNode()); - - if (needGenerateData) - { - ls->UpdateGenerateDataTime(); - - m_PropAssembly->VisibilityOn(); - - if (m_PropAssembly->GetParts()->IsItemPresent(m_SpheresActor)) - m_PropAssembly->RemovePart(m_SpheresActor); - if (m_PropAssembly->GetParts()->IsItemPresent(m_ContourActor)) - m_PropAssembly->RemovePart(m_ContourActor); - - m_Spheres->RemoveAllInputs(); - m_Contour->Initialize(); - - mitk::Mesh::Pointer input = const_cast<mitk::Mesh *>(this->GetInput()); - input->Update(); - - mitk::Mesh::DataType::Pointer itkMesh = input->GetMesh(this->GetTimestep()); - - if (itkMesh.GetPointer() == nullptr) - { - m_PropAssembly->VisibilityOff(); - return; - } - - mitk::Mesh::PointsContainer::Iterator i; - - int j; - - float floatRgba[4] = {1.0f, 1.0f, 1.0f, 1.0f}; - double doubleRgba[4] = {1.0f, 1.0f, 1.0f, 1.0f}; - mitk::Color tmpColor; - - // check for color prop and use it for rendering if it exists - m_DataNode->GetColor(floatRgba, nullptr); - - if (dynamic_cast<mitk::ColorProperty *>(this->GetDataNode()->GetProperty("unselectedcolor")) != nullptr) - { - tmpColor = dynamic_cast<mitk::ColorProperty *>(this->GetDataNode()->GetProperty("unselectedcolor"))->GetValue(); - floatRgba[0] = tmpColor[0]; - floatRgba[1] = tmpColor[1]; - floatRgba[2] = tmpColor[2]; - floatRgba[3] = 1.0f; //!!define a new ColorProp to be able to pass alpha value - doubleRgba[0] = floatRgba[0]; - doubleRgba[1] = floatRgba[1]; - doubleRgba[2] = floatRgba[2]; - doubleRgba[3] = floatRgba[3]; - } - - if (itkMesh->GetNumberOfPoints() > 0) - { - // build m_Spheres->GetOutput() vtkPolyData - float pointSize = 2.0; - mitk::FloatProperty::Pointer pointSizeProp = - dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetProperty("pointsize")); - if (pointSizeProp.IsNotNull()) - pointSize = pointSizeProp->GetValue(); - - for (j = 0, i = itkMesh->GetPoints()->Begin(); i != itkMesh->GetPoints()->End(); i++, j++) - { - vtkSmartPointer<vtkSphereSource> sphere = vtkSmartPointer<vtkSphereSource>::New(); - - sphere->SetRadius(pointSize); - sphere->SetCenter(i.Value()[0], i.Value()[1], i.Value()[2]); - - m_Spheres->AddInputConnection(sphere->GetOutputPort()); - sphere->Delete(); - } - - // setup mapper, actor and add to assembly - m_SpheresMapper->SetInputConnection(m_Spheres->GetOutputPort()); - m_SpheresActor->GetProperty()->SetColor(doubleRgba); - m_PropAssembly->AddPart(m_SpheresActor); - } - - if (itkMesh->GetNumberOfCells() > 0) - { -// build m_Contour vtkPolyData -#ifdef VCL_VC60 - itkExceptionMacro(<< "MeshVtkMapper3D currently not working for MS Visual C++ 6.0, because MeshUtils are " - "currently not supported."); -#else - m_Contour = - MeshUtil<mitk::Mesh::MeshType>::MeshToPolyData(itkMesh.GetPointer(), false, false, 0, nullptr, m_Contour); -#endif - - if (m_Contour->GetNumberOfCells() > 0) - { - // setup mapper, actor and add to assembly - m_ContourMapper->SetInputData(m_Contour); - bool wireframe = true; - GetDataNode()->GetVisibility(wireframe, nullptr, "wireframe"); - if (wireframe) - m_ContourActor->GetProperty()->SetRepresentationToWireframe(); - else - m_ContourActor->GetProperty()->SetRepresentationToSurface(); - m_ContourActor->GetProperty()->SetColor(doubleRgba); - m_PropAssembly->AddPart(m_ContourActor); - } - } - } - - bool visible = true; - GetDataNode()->GetVisibility(visible, renderer, "visible"); - - if (!visible) - { - m_SpheresActor->VisibilityOff(); - m_ContourActor->VisibilityOff(); - return; - } - - bool makeContour = false; - this->GetDataNode()->GetBoolProperty("show contour", makeContour); - - if (makeContour) - { - m_ContourActor->VisibilityOn(); - } - else - { - m_ContourActor->VisibilityOff(); - } - - bool showPoints = true; - this->GetDataNode()->GetBoolProperty("show points", showPoints); - if (showPoints) - { - m_SpheresActor->VisibilityOn(); - } - else - { - m_SpheresActor->VisibilityOff(); - } -} - -void mitk::MeshVtkMapper3D::ResetMapper(BaseRenderer * /*renderer*/) -{ - m_PropAssembly->VisibilityOff(); -} diff --git a/Modules/SceneSerializationBase/test/mitkPropertySerializationTest.cpp b/Modules/SceneSerializationBase/test/mitkPropertySerializationTest.cpp index 9171a6ce5b..c6cfe3b656 100644 --- a/Modules/SceneSerializationBase/test/mitkPropertySerializationTest.cpp +++ b/Modules/SceneSerializationBase/test/mitkPropertySerializationTest.cpp @@ -1,273 +1,199 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "mitkTestingMacros.h" #include "mitkCoreObjectFactory.h" #include "mitkBaseProperty.h" #include "mitkProperties.h" #include <mitkAnnotationProperty.h> #include <mitkClippingProperty.h> #include <mitkColorProperty.h> #include <mitkEnumerationProperty.h> -/* -#include <mitkGridRepresentationProperty.h> -#include <mitkGridVolumeMapperProperty.h> -*/ #include <mitkModalityProperty.h> -//#include <mitkOdfNormalizationMethodProperty.h> -//#include <mitkOdfScaleByProperty.h> #include <mitkGroupTagProperty.h> #include <mitkLevelWindowProperty.h> #include <mitkLookupTableProperty.h> #include <mitkPlaneOrientationProperty.h> #include <mitkStringProperty.h> #include <mitkTransferFunctionProperty.h> #include <mitkVtkInterpolationProperty.h> #include <mitkVtkRepresentationProperty.h> #include <mitkVtkResliceInterpolationProperty.h> #include <mitkVtkScalarModeProperty.h> #include <mitkVtkVolumeRenderingProperty.h> #include "mitkBasePropertySerializer.h" #include "mitkPropertyList.h" #include "mitkPropertyListSerializer.h" #include <mitkImage.h> #include <mitkPointSet.h> #include <mitkSurface.h> #include <mitkVtkWidgetRendering.h> -/* -#include <mitkCone.h> -#include <mitkContour.h> -#include <mitkContourSet.h> -#include <mitkCuboid.h> -#include <mitkCylinder.h> -#include <mitkEllipsoid.h> -#include <mitkExtrudedContour.h> -#include <mitkMesh.h> -#include <mitkPlane.h> -#include <mitkUnstructuredGrid.h> -*/ - void TestAllProperties(const mitk::PropertyList *propList); /**Documentation * \brief Test for all PropertySerializer classes. * */ int mitkPropertySerializationTest(int /* argc */, char * /*argv*/ []) { MITK_TEST_BEGIN("PropertySerializationTest"); mitk::PropertyListSerializer::Pointer serializer = mitk::PropertyListSerializer::New(); // make sure something from the lib is actually used (registration of // serializers) /* build list of properties that will be serialized and deserialized */ mitk::PropertyList::Pointer propList = mitk::PropertyList::New(); propList->SetProperty("booltrue", mitk::BoolProperty::New(true)); propList->SetProperty("boolfalse", mitk::BoolProperty::New(false)); propList->SetProperty("int", mitk::IntProperty::New(-32)); propList->SetProperty("float", mitk::FloatProperty::New(-31.337)); propList->SetProperty("double", mitk::DoubleProperty::New(-31.337)); propList->SetProperty("string", mitk::StringProperty::New("Hello MITK")); mitk::Point3D p3d; mitk::FillVector3D(p3d, 1.0, 2.2, -3.3); propList->SetProperty("p3d", mitk::Point3dProperty::New(p3d)); mitk::Point3I p3i; mitk::FillVector3D(p3i, 1, 2, -3); propList->SetProperty("p3i", mitk::Point3iProperty::New(p3i)); mitk::Point4D p4d; mitk::FillVector4D(p4d, 1.5, 2.6, -3.7, 4.44); propList->SetProperty("p4d", mitk::Point4dProperty::New(p4d)); mitk::Vector3D v3d; mitk::FillVector3D(v3d, 1.0, 2.2, -3.3); propList->SetProperty("v3d", mitk::Vector3DProperty::New(v3d)); propList->SetProperty("annotation", mitk::AnnotationProperty::New("My Annotation", p3d)); propList->SetProperty("clipping", mitk::ClippingProperty::New(p3d, v3d)); propList->SetProperty("color", mitk::ColorProperty::New(1.0, 0.2, 0.2)); - // mitk::EnumerationProperty::Pointer en = mitk::EnumerationProperty::New(); - // en->AddEnum("PC", 1); en->AddEnum("Playstation", 2); en->AddEnum("Wii", 111); en->AddEnum("XBox", 7); - // en->SetValue("XBox"); - // propList->SetProperty("enum", en); - /* - propList->SetProperty("gridrep", mitk::GridRepresentationProperty::New(2)); - propList->SetProperty("gridvol", mitk::GridVolumeMapperProperty::New(0)); - */ propList->SetProperty("modality", mitk::ModalityProperty::New("Color Doppler")); - // propList->SetProperty("OdfNormalizationMethodProperty", mitk::OdfNormalizationMethodProperty::New("Global - // Maximum")); - // propList->SetProperty("OdfScaleByProperty", mitk::OdfScaleByProperty::New("Principal Curvature")); propList->SetProperty("PlaneOrientationProperty", mitk::PlaneOrientationProperty::New("Arrows in positive direction")); propList->SetProperty("VtkInterpolationProperty", mitk::VtkInterpolationProperty::New("Gouraud")); propList->SetProperty("VtkRepresentationProperty", mitk::VtkRepresentationProperty::New("Surface")); propList->SetProperty("VtkResliceInterpolationProperty", mitk::VtkResliceInterpolationProperty::New("Cubic")); propList->SetProperty("VtkScalarModeProperty", mitk::VtkScalarModeProperty::New("PointFieldData")); propList->SetProperty("VtkVolumeRenderingProperty", mitk::VtkVolumeRenderingProperty::New("COMPOSITE")); mitk::BoolLookupTable blt; blt.SetTableValue(0, true); blt.SetTableValue(1, false); blt.SetTableValue(2, true); propList->SetProperty("BoolLookupTableProperty", mitk::BoolLookupTableProperty::New(blt)); mitk::FloatLookupTable flt; flt.SetTableValue(0, 3.1); flt.SetTableValue(1, 3.3); flt.SetTableValue(2, 7.0); propList->SetProperty("FloatLookupTableProperty", mitk::FloatLookupTableProperty::New(flt)); mitk::IntLookupTable ilt; ilt.SetTableValue(0, 3); ilt.SetTableValue(1, 2); ilt.SetTableValue(2, 11); propList->SetProperty("IntLookupTableProperty", mitk::IntLookupTableProperty::New(ilt)); mitk::StringLookupTable slt; slt.SetTableValue(0, "Hello"); slt.SetTableValue(1, "MITK"); slt.SetTableValue(2, "world"); propList->SetProperty("StringLookupTableProperty", mitk::StringLookupTableProperty::New(slt)); propList->SetProperty("GroupTagProperty", mitk::GroupTagProperty::New()); propList->SetProperty("LevelWindowProperty", mitk::LevelWindowProperty::New(mitk::LevelWindow(100.0, 50.0))); mitk::LookupTable::Pointer lt = mitk::LookupTable::New(); lt->ChangeOpacityForAll(0.25); lt->ChangeOpacity(17, 0.88); propList->SetProperty("LookupTableProperty", mitk::LookupTableProperty::New(lt)); propList->SetProperty("StringProperty", mitk::StringProperty::New("Oh why, gruel world")); - // mitk::TransferFunction::Pointer tf = mitk::TransferFunction::New(); - // tf->SetTransferFunctionMode(1); - // propList->SetProperty("TransferFunctionProperty", mitk::TransferFunctionProperty::New(tf)); MITK_TEST_CONDITION_REQUIRED(propList->GetMap()->size() > 0, "Initialize PropertyList"); TestAllProperties(propList); /* test default property lists of basedata objects */ // activate the following tests after MaterialProperty is deleted mitk::DataNode::Pointer node = mitk::DataNode::New(); node->SetData(mitk::PointSet::New()); TestAllProperties(node->GetPropertyList()); node->SetData(mitk::Image::New()); TestAllProperties(node->GetPropertyList()); node->SetData(mitk::Surface::New()); TestAllProperties(node->GetPropertyList()); node->SetData(mitk::VtkWidgetRendering::New()); TestAllProperties(node->GetPropertyList()); - /* - node->SetData(mitk::Contour::New()); - TestAllProperties(node->GetPropertyList()); - node->SetData(mitk::ContourSet::New()); - TestAllProperties(node->GetPropertyList()); - node->SetData(mitk::Mesh::New()); - TestAllProperties(node->GetPropertyList()); - node->SetData(mitk::Cone::New()); - TestAllProperties(node->GetPropertyList()); - node->SetData(mitk::Cuboid::New()); - TestAllProperties(node->GetPropertyList()); - node->SetData(mitk::Cylinder::New()); - TestAllProperties(node->GetPropertyList()); - node->SetData(mitk::Ellipsoid::New()); - TestAllProperties(node->GetPropertyList()); - node->SetData(mitk::ExtrudedContour::New()); - TestAllProperties(node->GetPropertyList()); - node->SetData(mitk::Plane::New()); - TestAllProperties(node->GetPropertyList()); - //node->SetData(mitk::TrackingVolume::New()); // TrackingVolume is in IGT Module, it does not have special - properties, therefore we skip it here - //TestAllProperties(node->GetPropertyList()); - node->SetData(mitk::UnstructuredGrid::New()); - TestAllProperties(node->GetPropertyList()); - */ - - /* untested base data types: - BaseDataTestImplementation - RenderWindowFrame - GeometryData - mitk::PlaneGeometryData - GradientBackground - ItkBaseDataAdapter - SlicedData - OdfImage - SeedsImage - TensorImage - BoundingObject - BoundingObjectGroup - */ - MITK_TEST_END(); } void TestAllProperties(const mitk::PropertyList *propList) { assert(propList); /* try to serialize each property in the list, then deserialize again and check for equality */ for (auto it = propList->GetMap()->begin(); it != propList->GetMap()->end(); ++it) { const mitk::BaseProperty *prop = it->second; // construct name of serializer class std::string serializername = std::string(prop->GetNameOfClass()) + "Serializer"; std::list<itk::LightObject::Pointer> allSerializers = itk::ObjectFactoryBase::CreateAllInstance(serializername.c_str()); MITK_TEST_CONDITION(allSerializers.size() > 0, std::string("Creating serializers for ") + serializername); if (allSerializers.size() == 0) { MITK_TEST_OUTPUT(<< "serialization not possible, skipping " << prop->GetNameOfClass()); continue; } if (allSerializers.size() > 1) { MITK_TEST_OUTPUT(<< "Warning: " << allSerializers.size() << " serializers found for " << prop->GetNameOfClass() << "testing only the first one."); } auto *serializer = dynamic_cast<mitk::BasePropertySerializer *>(allSerializers.begin()->GetPointer()); MITK_TEST_CONDITION(serializer != nullptr, serializername + std::string(" is valid")); if (serializer != nullptr) { serializer->SetProperty(prop); TiXmlElement *valueelement = nullptr; try { valueelement = serializer->Serialize(); } catch (...) { } MITK_TEST_CONDITION(valueelement != nullptr, std::string("Serialize property with ") + serializername); if (valueelement == nullptr) { MITK_TEST_OUTPUT(<< "serialization failed, skipping deserialization"); continue; } mitk::BaseProperty::Pointer deserializedProp = serializer->Deserialize(valueelement); MITK_TEST_CONDITION(deserializedProp.IsNotNull(), "serializer created valid property"); if (deserializedProp.IsNotNull()) { MITK_TEST_CONDITION(*(deserializedProp.GetPointer()) == *prop, "deserialized property equals initial property for type " << prop->GetNameOfClass()); } } else { MITK_TEST_OUTPUT(<< "created serializer object is of class " << allSerializers.begin()->GetPointer()->GetNameOfClass()) } } // for all properties }