renderIter(renderWindowPart->GetQmitkRenderWindows());
while (renderIter.hasNext())
{
renderIter.next();
m_Controls->renderWindowComboBox->addItem(renderIter.key());
}
RenderWindowSelected(m_Controls->renderWindowComboBox->currentText());
m_TimeStepper.reset(new QmitkStepperAdapter(m_Controls->sliceNavigatorTime,
renderWindowPart->GetTimeNavigationController()->GetTime(),
"sliceNavigatorTimeFromSimpleExample"));
m_MovieStepper.reset(new QmitkStepperAdapter(m_Controls->movieNavigatorTime,
renderWindowPart->GetTimeNavigationController()->GetTime(),
"movieNavigatorTimeFromSimpleExample"));
m_Parent->setEnabled(true);
}
void QmitkSimpleExampleView::RenderWindowPartDeactivated(mitk::IRenderWindowPart * /*renderWindowPart*/)
{
m_Parent->setEnabled(false);
m_SliceStepper.reset();
m_TimeStepper.reset();
m_MovieStepper.reset();
m_Controls->renderWindowComboBox->clear();
}
void QmitkSimpleExampleView::CreateConnections()
{
if (m_Controls)
{
connect(m_Controls->renderWindowComboBox,
SIGNAL(currentIndexChanged(QString)),
this,
SLOT(RenderWindowSelected(QString)));
connect(m_Controls->stereoSelect, SIGNAL(activated(int)), this, SLOT(StereoSelectionChanged(int)));
connect(m_Controls->reInitializeNavigatorsButton, SIGNAL(clicked()), this, SLOT(InitNavigators()));
connect(m_Controls->genMovieButton, SIGNAL(clicked()), this, SLOT(GenerateMovie()));
connect(m_Controls->m_TakeScreenshotBtn, SIGNAL(clicked()), this, SLOT(OnTakeScreenshot()));
connect(m_Controls->m_TakeHighResScreenShotBtn, SIGNAL(clicked()), this, SLOT(OnTakeHighResolutionScreenshot()));
}
}
void QmitkSimpleExampleView::InitNavigators()
{
/* get all nodes that have not set "includeInBoundingBox" to false */
mitk::NodePredicateNot::Pointer pred = mitk::NodePredicateNot::New(
mitk::NodePredicateProperty::New("includeInBoundingBox", mitk::BoolProperty::New(false)));
mitk::DataStorage::SetOfObjects::ConstPointer rs = this->GetDataStorage()->GetSubset(pred);
/* calculate bounding geometry of these nodes */
auto bounds = this->GetDataStorage()->ComputeBoundingGeometry3D(rs);
/* initialize the views to the bounding geometry */
m_NavigatorsInitialized = mitk::RenderingManager::GetInstance()->InitializeViews(bounds);
}
/**
* Returns path to the ffmpeg lib if configured in preferences.
*
* This implementation has been reused from MovieMaker view.
*
* @return The path to ffmpeg lib or empty string if not configured.
*/
QString QmitkSimpleExampleView::GetFFmpegPath() const
{
berry::IPreferences::Pointer preferences =
berry::Platform::GetPreferencesService()->GetSystemPreferences()->Node("/org.mitk.gui.qt.ext.externalprograms");
return preferences.IsNotNull() ? preferences->Get("ffmpeg", "") : "";
}
/**
* Reads pixels from specified render window.
*
* This implementation has been reused from MovieMaker view.
*
* @param renderWindow
* @param x
* @param y
* @param width
* @param height
* @return
*/
static unsigned char *ReadPixels(vtkRenderWindow *renderWindow, int x, int y, int width, int height)
{
if (renderWindow == nullptr)
return nullptr;
unsigned char *frame = new unsigned char[width * height * 3];
renderWindow->MakeCurrent();
glReadPixels(x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE, frame);
return frame;
}
/**
* Records a movie from the selected render window with a default frame rate of 30 Hz.
*
* Parts of this implementation have been reused from MovieMaker view.
*/
void QmitkSimpleExampleView::GenerateMovie()
{
QmitkRenderWindow *movieRenderWindow = GetSelectedRenderWindow();
mitk::Stepper::Pointer stepper = movieRenderWindow->GetSliceNavigationController()->GetSlice();
QmitkFFmpegWriter *movieWriter = new QmitkFFmpegWriter(m_Parent);
const QString ffmpegPath = GetFFmpegPath();
if (ffmpegPath.isEmpty())
{
QMessageBox::information(
nullptr,
"Movie Maker",
"Set path to FFmpeg1 in preferences (Window -> Preferences... "
"(Ctrl+P) -> External Programs) to be able to record your movies to video files.
"
"If you are using Linux, chances are good that FFmpeg is included in the official package "
"repositories.
"
"[1] Download FFmpeg from ffmpeg.org
");
return;
}
movieWriter->SetFFmpegPath(GetFFmpegPath());
- vtkRenderWindow *renderWindow = movieRenderWindow->GetRenderWindow();
+ vtkRenderWindow *renderWindow = movieRenderWindow->renderWindow();
if (renderWindow == nullptr)
return;
const int border = 3;
const int x = border;
const int y = border;
int width = renderWindow->GetSize()[0] - border * 2;
int height = renderWindow->GetSize()[1] - border * 2;
if (width & 1)
--width;
if (height & 1)
--height;
if (width < 16 || height < 16)
return;
movieWriter->SetSize(width, height);
movieWriter->SetFramerate(30);
QString saveFileName = QFileDialog::getSaveFileName(nullptr, "Specify a filename", "", "Movie (*.mp4)");
if (saveFileName.isEmpty())
return;
if (!saveFileName.endsWith(".mp4"))
saveFileName += ".mp4";
movieWriter->SetOutputPath(saveFileName);
const unsigned int numberOfFrames = stepper->GetSteps() - stepper->GetPos();
try
{
movieWriter->Start();
for (unsigned int currentFrame = 0; currentFrame < numberOfFrames; ++currentFrame)
{
mitk::RenderingManager::GetInstance()->ForceImmediateUpdateAll();
renderWindow->MakeCurrent();
unsigned char *frame = ReadPixels(renderWindow, x, y, width, height);
movieWriter->WriteFrame(frame);
delete[] frame;
stepper->Next();
}
movieWriter->Stop();
mitk::RenderingManager::GetInstance()->ForceImmediateUpdateAll();
}
catch (const mitk::Exception &exception)
{
mitk::RenderingManager::GetInstance()->ForceImmediateUpdateAll();
QMessageBox::critical(nullptr, "Generate Movie", exception.GetDescription());
}
}
void QmitkSimpleExampleView::StereoSelectionChanged(int id)
{
/* From vtkRenderWindow.h tells us about stereo rendering:
Set/Get what type of stereo rendering to use. CrystalEyes mode uses frame-sequential capabilities available in OpenGL
to drive LCD shutter glasses and stereo projectors. RedBlue mode is a simple type of stereo for use with red-blue
glasses. Anaglyph mode is a superset of RedBlue mode, but the color output channels can be configured using the
AnaglyphColorMask and the color of the original image can be (somewhat maintained using AnaglyphColorSaturation; the
default colors for Anaglyph mode is red-cyan. Interlaced stereo mode produces a composite image where horizontal
lines alternate between left and right views. StereoLeft and StereoRight modes choose one or the other stereo view.
Dresden mode is yet another stereoscopic interleaving.
*/
mitk::IRenderWindowPart *renderWindowPart = this->GetRenderWindowPart();
vtkRenderWindow *vtkrenderwindow = renderWindowPart->GetQmitkRenderWindow("3d")->GetVtkRenderWindow();
// note: foreground vtkRenderers (at least the department logo renderer) produce errors in stereoscopic visualization.
// Therefore, we disable the logo visualization during stereo rendering.
switch (id)
{
case 0:
vtkrenderwindow->StereoRenderOff();
break;
case 1:
vtkrenderwindow->SetStereoTypeToRedBlue();
vtkrenderwindow->StereoRenderOn();
renderWindowPart->EnableDecorations(false, QStringList(mitk::IRenderWindowPart::DECORATION_LOGO));
break;
case 2:
vtkrenderwindow->SetStereoTypeToDresden();
vtkrenderwindow->StereoRenderOn();
renderWindowPart->EnableDecorations(false, QStringList(mitk::IRenderWindowPart::DECORATION_LOGO));
break;
}
mitk::BaseRenderer::GetInstance(vtkrenderwindow)->SetMapperID(mitk::BaseRenderer::Standard3D);
renderWindowPart->RequestUpdate();
}
QmitkRenderWindow *QmitkSimpleExampleView::GetSelectedRenderWindow() const
{
QString id = m_Controls->renderWindowComboBox->currentText();
if (id.isEmpty())
{
return nullptr;
}
else
{
return this->GetRenderWindowPart()->GetQmitkRenderWindow(id);
}
}
void QmitkSimpleExampleView::OnTakeHighResolutionScreenshot()
{
QString filter;
QString fileName = QFileDialog::getSaveFileName(
nullptr, "Save screenshot to...", QDir::currentPath(), m_PNGExtension + ";;" + m_JPGExtension, &filter);
vtkRenderer *renderer = this->GetSelectedRenderWindow()->GetRenderer()->GetVtkRenderer();
if (renderer == nullptr)
return;
this->TakeScreenshot(renderer, 4, fileName, filter);
}
void QmitkSimpleExampleView::OnTakeScreenshot()
{
QString filter;
QString fileName = QFileDialog::getSaveFileName(
nullptr, "Save screenshot to...", QDir::currentPath(), m_PNGExtension + ";;" + m_JPGExtension, &filter);
QmitkRenderWindow *renWin = this->GetSelectedRenderWindow();
if (renWin == nullptr)
return;
vtkRenderer *renderer = renWin->GetRenderer()->GetVtkRenderer();
if (renderer == nullptr)
return;
this->TakeScreenshot(renderer, 1, fileName, filter);
}
void QmitkSimpleExampleView::TakeScreenshot(vtkRenderer *renderer,
unsigned int magnificationFactor,
QString fileName,
QString filter)
{
if ((renderer == nullptr) || (magnificationFactor < 1) || fileName.isEmpty())
return;
bool doubleBuffering(renderer->GetRenderWindow()->GetDoubleBuffer());
renderer->GetRenderWindow()->DoubleBufferOff();
vtkImageWriter *fileWriter = nullptr;
QFileInfo fi(fileName);
QString suffix = fi.suffix().toLower();
if (suffix.isEmpty() || (suffix != "png" && suffix != "jpg" && suffix != "jpeg"))
{
if (filter == m_PNGExtension)
{
suffix = "png";
}
else if (filter == m_JPGExtension)
{
suffix = "jpg";
}
fileName += "." + suffix;
}
if (suffix.compare("jpg", Qt::CaseInsensitive) == 0 || suffix.compare("jpeg", Qt::CaseInsensitive) == 0)
{
vtkJPEGWriter *w = vtkJPEGWriter::New();
w->SetQuality(100);
w->ProgressiveOff();
fileWriter = w;
}
else // default is png
{
fileWriter = vtkPNGWriter::New();
}
vtkRenderLargeImage *magnifier = vtkRenderLargeImage::New();
magnifier->SetInput(renderer);
magnifier->SetMagnification(magnificationFactor);
fileWriter->SetInputConnection(magnifier->GetOutputPort());
fileWriter->SetFileName(fileName.toLatin1());
// vtkRenderLargeImage has problems with different layers, therefore we have to
// temporarily deactivate all other layers.
// we set the background to white, because it is nicer than black...
double oldBackground[3];
renderer->GetBackground(oldBackground);
double white[] = {1.0, 1.0, 1.0};
renderer->SetBackground(white);
mitk::IRenderWindowPart *renderWindowPart = this->GetRenderWindowPart();
renderWindowPart->EnableDecorations(false);
fileWriter->Write();
fileWriter->Delete();
renderWindowPart->EnableDecorations(true);
renderer->SetBackground(oldBackground);
renderer->GetRenderWindow()->SetDoubleBuffer(doubleBuffering);
}
void QmitkSimpleExampleView::RenderWindowSelected(const QString &id)
{
if (!id.isEmpty())
{
m_SliceStepper.reset(new QmitkStepperAdapter(
m_Controls->sliceNavigator,
this->GetRenderWindowPart()->GetQmitkRenderWindow(id)->GetSliceNavigationController()->GetSlice(),
"sliceNavigatorFromSimpleExample"));
}
}
diff --git a/Modules/Classification/CLMiniApps/CMakeLists.txt b/Modules/Classification/CLMiniApps/CMakeLists.txt
index 3755b73a83..6e45122c9a 100644
--- a/Modules/Classification/CLMiniApps/CMakeLists.txt
+++ b/Modules/Classification/CLMiniApps/CMakeLists.txt
@@ -1,117 +1,117 @@
option(BUILD_ClassificationMiniApps "Build commandline tools for classification" OFF)
if(BUILD_ClassificationMiniApps OR MITK_BUILD_ALL_APPS)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
)
# list of miniapps
# if an app requires additional dependencies
# they are added after a "^^" and separated by "_"
set( classificationminiapps
RandomForestTraining^^MitkCLVigraRandomForest
NativeHeadCTSegmentation^^MitkCLVigraRandomForest
ManualSegmentationEvaluation^^MitkCLVigraRandomForest
CLScreenshot^^MitkCore_MitkQtWidgetsExt_MitkCLUtilities
CLDicom2Nrrd^^MitkCore
CLResampleImageToReference^^MitkCore
CLGlobalImageFeatures^^MitkCLUtilities_MitkQtWidgetsExt
CLMRNormalization^^MitkCLUtilities_MitkCLMRUtilities
CLStaple^^MitkCLUtilities
CLVoxelFeatures^^MitkCLUtilities
CLPolyToNrrd^^
CLPlanarFigureToNrrd^^MitkCore_MitkSegmentation_MitkMultilabel
CLSimpleVoxelClassification^^MitkDataCollection_MitkCLVigraRandomForest
CLVoxelClassification^^MitkDataCollection_MitkCLImportanceWeighting_MitkCLVigraRandomForest
CLBrainMask^^MitkCLUtilities
XRaxSimulationFromCT^^MitkCLUtilities
CLRandomSampling^^MitkCore_MitkCLUtilities
CLRemoveEmptyVoxels^^MitkCore
CLN4^^MitkCore
CLSkullMask^^MitkCore
CLPointSetToSegmentation^^
CLMultiForestPrediction^^MitkDataCollection_MitkCLVigraRandomForest
CLNrrdToPoly^^MitkCore
CL2Dto3DImage^^MitkCore
CLWeighting^^MitkCore_MitkCLImportanceWeighting_MitkCLUtilities
CLOverlayRoiCenterOfMass^^MitkCore_MitkCLUtilities_MitkQtWidgetsExt
CLLungSegmentation^^MitkCore_MitkSegmentation_MitkMultilabel
)
foreach(classificationminiapps ${classificationminiapps})
# extract mini app name and dependencies
string(REPLACE "^^" "\\;" miniapp_info ${classificationminiapps})
set(miniapp_info_list ${miniapp_info})
list(GET miniapp_info_list 0 appname)
list(GET miniapp_info_list 1 raw_dependencies)
string(REPLACE "_" "\\;" dependencies "${raw_dependencies}")
set(dependencies_list ${dependencies})
mitk_create_executable(${appname}
DEPENDS MitkCore MitkCLCore MitkCommandLine ${dependencies_list}
- PACKAGE_DEPENDS ITK Qt5|Core Vigra
+ PACKAGE_DEPENDS ITK Qt5|Core Vigra VTK|IOImage
CPP_FILES ${appname}.cpp
)
if(EXECUTABLE_IS_ENABLED)
# On Linux, create a shell script to start a relocatable application
if(UNIX AND NOT APPLE)
install(PROGRAMS "${MITK_SOURCE_DIR}/CMake/RunInstalledApp.sh" DESTINATION "." RENAME ${EXECUTABLE_TARGET}.sh)
endif()
get_target_property(_is_bundle ${EXECUTABLE_TARGET} MACOSX_BUNDLE)
if(APPLE)
if(_is_bundle)
set(_target_locations ${EXECUTABLE_TARGET}.app)
set(${_target_locations}_qt_plugins_install_dir ${EXECUTABLE_TARGET}.app/Contents/MacOS)
set(_bundle_dest_dir ${EXECUTABLE_TARGET}.app/Contents/MacOS)
set(_qt_plugins_for_current_bundle ${EXECUTABLE_TARGET}.app/Contents/MacOS)
set(_qt_conf_install_dirs ${EXECUTABLE_TARGET}.app/Contents/Resources)
install(TARGETS ${EXECUTABLE_TARGET} BUNDLE DESTINATION . )
else()
if(NOT MACOSX_BUNDLE_NAMES)
set(_qt_conf_install_dirs bin)
set(_target_locations bin/${EXECUTABLE_TARGET})
set(${_target_locations}_qt_plugins_install_dir bin)
install(TARGETS ${EXECUTABLE_TARGET} RUNTIME DESTINATION bin)
else()
foreach(bundle_name ${MACOSX_BUNDLE_NAMES})
list(APPEND _qt_conf_install_dirs ${bundle_name}.app/Contents/Resources)
set(_current_target_location ${bundle_name}.app/Contents/MacOS/${EXECUTABLE_TARGET})
list(APPEND _target_locations ${_current_target_location})
set(${_current_target_location}_qt_plugins_install_dir ${bundle_name}.app/Contents/MacOS)
message( " set(${_current_target_location}_qt_plugins_install_dir ${bundle_name}.app/Contents/MacOS) ")
install(TARGETS ${EXECUTABLE_TARGET} RUNTIME DESTINATION ${bundle_name}.app/Contents/MacOS/)
endforeach()
endif()
endif()
else()
set(_target_locations bin/${EXECUTABLE_TARGET}${CMAKE_EXECUTABLE_SUFFIX})
set(${_target_locations}_qt_plugins_install_dir bin)
set(_qt_conf_install_dirs bin)
install(TARGETS ${EXECUTABLE_TARGET} RUNTIME DESTINATION bin)
endif()
endif()
endforeach()
mitk_create_executable(CLMatchPointReg
DEPENDS MitkCore MitkCLUtilities MitkMatchPointRegistration MitkCommandLine MitkMatchPointRegistrationUI
PACKAGE_DEPENDS ITK Qt5|Core Vigra MatchPoint
CPP_FILES CLMatchPointReg.cpp
)
# On Linux, create a shell script to start a relocatable application
if(UNIX AND NOT APPLE)
install(PROGRAMS "${MITK_SOURCE_DIR}/CMake/RunInstalledApp.sh" DESTINATION "." RENAME ${EXECUTABLE_TARGET}.sh)
endif()
if(EXECUTABLE_IS_ENABLED)
MITK_INSTALL_TARGETS(EXECUTABLES ${EXECUTABLE_TARGET})
endif()
endif()
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
#include
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):
*
*
* PointSetEvent subsumes all PointSet events
* PointSetMoveEvent issued when a point of the PointSet is moved
* PointSetSizeChangeEvent subsumes add and remove events
* PointSetAddEvent issued when a point is added to the PointSet
* PointSetRemoveEvent issued when a point is removed from the PointSet
*
* \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 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
MeshTraits;
typedef itk::Mesh 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 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/Core/src/IO/mitkSurfaceStlIO.cpp b/Modules/Core/src/IO/mitkSurfaceStlIO.cpp
index e64e9a1634..21aeb441e0 100644
--- a/Modules/Core/src/IO/mitkSurfaceStlIO.cpp
+++ b/Modules/Core/src/IO/mitkSurfaceStlIO.cpp
@@ -1,160 +1,160 @@
/*============================================================================
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 "mitkSurfaceStlIO.h"
#include "mitkIOMimeTypes.h"
#include "mitkLocaleSwitch.h"
#include "mitkSurface.h"
#include
#include
#include
#include
#include
#include
#include
namespace mitk
{
- std::string SurfaceStlIO::OPTION_MERGE_POINTS()
- {
- static std::string s = "Merge points";
- return s;
- }
+ // std::string SurfaceStlIO::OPTION_MERGE_POINTS()
+ // {
+ // static std::string s = "Merge points";
+ // return s;
+ // }
std::string SurfaceStlIO::OPTION_TAG_SOLIDS()
{
static std::string s = "Tag solids";
return s;
}
std::string SurfaceStlIO::OPTION_CLEAN()
{
static std::string s = "Clean poly data";
return s;
}
SurfaceStlIO::SurfaceStlIO()
: SurfaceVtkIO(Surface::GetStaticNameOfClass(), IOMimeTypes::STEREOLITHOGRAPHY_MIMETYPE(), "Stereolithography")
{
Options defaultOptions;
- defaultOptions[OPTION_MERGE_POINTS()] = us::Any(true);
+ // defaultOptions[OPTION_MERGE_POINTS()] = us::Any(true);
defaultOptions[OPTION_TAG_SOLIDS()] = us::Any(false);
defaultOptions[OPTION_CLEAN()] = us::Any(true);
this->SetDefaultReaderOptions(defaultOptions);
this->RegisterService();
}
std::vector> SurfaceStlIO::DoRead()
{
LocaleSwitch localeSwitch("C");
Options options = this->GetReaderOptions();
mitk::Surface::Pointer output = mitk::Surface::New();
vtkSmartPointer stlReader = vtkSmartPointer::New();
stlReader->SetFileName(this->GetLocalFileName().c_str());
- bool mergePoints = true;
+ // bool mergePoints = true;
bool tagSolids = false;
bool cleanData = true;
try
{
- mergePoints = us::any_cast(options[OPTION_MERGE_POINTS()]);
+ // mergePoints = us::any_cast(options[OPTION_MERGE_POINTS()]);
tagSolids = us::any_cast(options[OPTION_TAG_SOLIDS()]);
cleanData = us::any_cast(options[OPTION_CLEAN()]);
}
catch (const us::BadAnyCastException &e)
{
MITK_WARN << "Unexpected error: " << e.what();
}
- stlReader->SetMerging(mergePoints);
+ // stlReader->SetMerging(mergePoints);
stlReader->SetScalarTags(tagSolids);
vtkSmartPointer normalsGenerator = vtkSmartPointer::New();
normalsGenerator->SetInputConnection(stlReader->GetOutputPort());
vtkSmartPointer algo = normalsGenerator;
if (cleanData)
{
vtkSmartPointer cleanPolyDataFilter = vtkSmartPointer::New();
cleanPolyDataFilter->SetInputConnection(normalsGenerator->GetOutputPort());
cleanPolyDataFilter->PieceInvariantOff();
cleanPolyDataFilter->ConvertLinesToPointsOff();
cleanPolyDataFilter->ConvertPolysToLinesOff();
cleanPolyDataFilter->ConvertStripsToPolysOff();
- if (mergePoints)
- {
+ // if (mergePoints)
+ // {
cleanPolyDataFilter->PointMergingOn();
- }
+ // }
algo = cleanPolyDataFilter;
}
algo->Update();
if (algo->GetOutput() != nullptr)
{
vtkSmartPointer surfaceWithNormals = algo->GetOutput();
output->SetVtkPolyData(surfaceWithNormals);
}
std::vector result;
result.push_back(output.GetPointer());
return result;
}
void SurfaceStlIO::Write()
{
LocaleSwitch localeSwitch("C");
ValidateOutputLocation();
const auto *input = dynamic_cast(this->GetInput());
const unsigned int timesteps = input->GetTimeGeometry()->CountTimeSteps();
for (unsigned int t = 0; t < timesteps; ++t)
{
std::string fileName;
vtkSmartPointer polyData = this->GetPolyData(t, fileName);
vtkSmartPointer triangleFilter = vtkSmartPointer::New();
triangleFilter->SetInputData(polyData);
vtkSmartPointer writer = vtkSmartPointer::New();
writer->SetInputConnection(triangleFilter->GetOutputPort());
// The vtk stl writer cannot write to streams
LocalFile localFile(this);
writer->SetFileName(localFile.GetFileName().c_str());
if (writer->Write() == 0 || writer->GetErrorCode() != 0)
{
mitkThrow() << "Error during surface writing"
<< (writer->GetErrorCode() ?
std::string(": ") + vtkErrorCode::GetStringFromErrorCode(writer->GetErrorCode()) :
std::string());
}
if (this->GetOutputStream() && input->GetTimeGeometry()->CountTimeSteps() > 1)
{
MITK_WARN << "Writing multiple time-steps to output streams is not supported. "
<< "Only the first time-step will be written";
break;
}
}
}
SurfaceStlIO *SurfaceStlIO::IOClone() const { return new SurfaceStlIO(*this); }
}
diff --git a/Modules/Core/src/IO/mitkSurfaceStlIO.h b/Modules/Core/src/IO/mitkSurfaceStlIO.h
index ffe36e1e60..2e95e8ab2e 100644
--- a/Modules/Core/src/IO/mitkSurfaceStlIO.h
+++ b/Modules/Core/src/IO/mitkSurfaceStlIO.h
@@ -1,45 +1,47 @@
/*============================================================================
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 _MITK_SURFACE_STL_IO_H_
#define _MITK_SURFACE_STL_IO_H_
#include "mitkSurfaceVtkIO.h"
namespace mitk
{
class SurfaceStlIO : public mitk::SurfaceVtkIO
{
public:
SurfaceStlIO();
// -------------- AbstractFileReader -------------
using AbstractFileReader::Read;
// -------------- AbstractFileWriter -------------
void Write() override;
protected:
std::vector> DoRead() override;
private:
SurfaceStlIO *IOClone() const override;
- static std::string OPTION_MERGE_POINTS();
+ // vtkSTLReader crashes with this option
+ // static std::string OPTION_MERGE_POINTS();
+
static std::string OPTION_TAG_SOLIDS();
static std::string OPTION_CLEAN();
};
}
#endif //_MITK_SURFACE_STL_IO_H_
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
-#include
-#include
-#include
-#include
-
-#include
-#include
-
-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 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
-#include
-#include
-#include
-#include
-#include
-//#include
-#include
-//#include
-//#include
-//#include
-#include
-#include
-#include
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include
-#include
-
-template
-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
-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
-class MeanCurvatureAccessor : public NullScalarAccessor
-{
-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
-class SimplexMeshAccessor : public NullScalarAccessor
-{
-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 >
-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 SwitchByCellType : public InsertImplementation
- {
- // typedef the itk cells we are interested in
- typedef typename itk::CellInterface
- CellInterfaceType;
- typedef itk::LineCell floatLineCell;
- typedef itk::TriangleCell floatTriangleCell;
- typedef itk::PolygonCell floatPolygonCell;
- typedef itk::QuadrilateralCell floatQuadrilateralCell;
- typedef itk::TetrahedronCell floatTetrahedronCell;
- typedef itk::HexahedronCell 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 ExactSwitchByCellType : public InsertImplementation
- {
- // typedef the itk cells we are interested in
- typedef typename itk::CellInterface
- CellInterfaceType;
- typedef itk::LineCell floatLineCell;
- typedef itk::TriangleCell floatTriangleCell;
- typedef itk::PolygonCell floatPolygonCell;
- typedef itk::QuadrilateralCell floatQuadrilateralCell;
- typedef itk::TetrahedronCell floatTetrahedronCell;
- typedef itk::HexahedronCell 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 SingleCellArrayUserVisitorType;
- typedef SwitchByCellType DistributeUserVisitorType;
- typedef ExactSwitchByCellType ExactUserVisitorType;
-
-public:
- typedef itk::MatrixOffsetTransformBase ITKTransformType;
- typedef itk::MatrixOffsetTransformBase 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 CellInterfaceType;
- typedef typename itk::TriangleCell 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,
- SingleCellArrayUserVisitorType>
- SingleCellArrayLineVisitor;
-
- /*!
- default SingleCellArray polygon cell visitior definition
- */
- typedef typename itk::CellInterfaceVisitorImplementation,
- SingleCellArrayUserVisitorType>
- SingleCellArrayPolygonVisitor;
-
- /*!
- default SingleCellArray triangle cell visitior definition
- */
- typedef typename itk::CellInterfaceVisitorImplementation<
- typename MeshType::CellPixelType,
- typename MeshType::CellTraits,
- itk::TriangleCell>,
- SingleCellArrayUserVisitorType>
- SingleCellArrayTriangleVisitor;
-
- /*!
- default SingleCellArray quad cell visitior definition
- */
- typedef typename itk::CellInterfaceVisitorImplementation<
- typename MeshType::CellPixelType,
- typename MeshType::CellTraits,
- itk::QuadrilateralCell>,
- SingleCellArrayUserVisitorType>
- SingleCellArrayQuadrilateralVisitor;
-
- /*!
- default SingleCellArray tetra cell visitior definition
- */
- typedef typename itk::CellInterfaceVisitorImplementation<
- typename MeshType::CellPixelType,
- typename MeshType::CellTraits,
- itk::TetrahedronCell>,
- SingleCellArrayUserVisitorType>
- SingleCellArrayTetrahedronVisitor;
-
- /*!
- default SingleCellArray hex cell visitior definition
- */
- typedef typename itk::CellInterfaceVisitorImplementation<
- typename MeshType::CellPixelType,
- typename MeshType::CellTraits,
- itk::HexahedronCell>,
- 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,
- DistributeUserVisitorType>
- DistributeLineVisitor;
-
- /*!
- default Distribute polygon cell visitior definition
- */
- typedef typename itk::CellInterfaceVisitorImplementation,
- DistributeUserVisitorType>
- DistributePolygonVisitor;
-
- /*!
- default Distribute triangle cell visitior definition
- */
- typedef typename itk::CellInterfaceVisitorImplementation<
- typename MeshType::CellPixelType,
- typename MeshType::CellTraits,
- itk::TriangleCell>,
- DistributeUserVisitorType>
- DistributeTriangleVisitor;
-
- /*!
- default Distribute quad cell visitior definition
- */
- typedef typename itk::CellInterfaceVisitorImplementation<
- typename MeshType::CellPixelType,
- typename MeshType::CellTraits,
- itk::QuadrilateralCell>,
- DistributeUserVisitorType>
- DistributeQuadrilateralVisitor;
-
- /*!
- default Distribute triangle cell visitior definition
- */
- typedef typename itk::CellInterfaceVisitorImplementation<
- typename MeshType::CellPixelType,
- typename MeshType::CellTraits,
- itk::TriangleCell>,
- 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(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(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 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 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 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::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 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();
- 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();
- 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(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(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(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(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(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(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(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(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(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(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(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 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(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(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(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(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(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(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
-#include
-#include
-#include
-#include
-
-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
#include
#include
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::New().GetPointer());
m_FileWriters.push_back(mitk::UnstructuredGridVtkWriter::New().GetPointer());
m_FileWriters.push_back(mitk::UnstructuredGridVtkWriter::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(data) != nullptr))
- {
- newMapper = mitk::MeshMapper2D::New();
- newMapper->SetDataNode(node);
- }
- else if ((dynamic_cast(data) != nullptr))
+ if ((dynamic_cast(data) != nullptr))
{
newMapper = mitk::VtkGLMapperWrapper::New(mitk::UnstructuredGridMapper2D::New().GetPointer());
newMapper->SetDataNode(node);
}
}
else if (id == mitk::BaseRenderer::Standard3D)
{
if ((dynamic_cast(data) != nullptr) && std::string("Image").compare(node->GetData()->GetNameOfClass())==0)
{
newMapper = mitk::VolumeMapperVtkSmart3D::New();
newMapper->SetDataNode(node);
}
- else if ((dynamic_cast(data) != nullptr))
- {
- newMapper = mitk::MeshVtkMapper3D::New();
- newMapper->SetDataNode(node);
- }
else if ((dynamic_cast(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(node->GetData());
if (image.IsNotNull() && image->IsInitialized())
{
mitk::VolumeMapperVtkSmart3D::SetDefaultProperties(node);
}
if (dynamic_cast(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("*.vtu", "VTK Unstructured Grid"));
m_FileExtensionsMap.insert(std::pair("*.vtk", "VTK Unstructured Grid"));
m_FileExtensionsMap.insert(std::pair("*.pvtu", "VTK Unstructured Grid"));
m_SaveFileExtensionsMap.insert(std::pair("*.pvtu", "VTK Parallel XML Unstructured Grid"));
m_SaveFileExtensionsMap.insert(std::pair("*.vtu", "VTK XML Unstructured Grid"));
m_SaveFileExtensionsMap.insert(std::pair("*.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/ImageStatistics/mitkExtendedLabelStatisticsImageFilter.hxx b/Modules/ImageStatistics/mitkExtendedLabelStatisticsImageFilter.hxx
index 794133be0a..05223f2105 100644
--- a/Modules/ImageStatistics/mitkExtendedLabelStatisticsImageFilter.hxx
+++ b/Modules/ImageStatistics/mitkExtendedLabelStatisticsImageFilter.hxx
@@ -1,756 +1,737 @@
/*============================================================================
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 _mitkExtendedLabelStatisticsImageFilter_hxx
#define _mitkExtendedLabelStatisticsImageFilter_hxx
#include "mitkExtendedLabelStatisticsImageFilter.h"
#include "itkImageRegionConstIteratorWithIndex.h"
#include "itkImageRegionConstIterator.h"
#include
#include
#include "mitkNumericConstants.h"
#include "mitkLogMacros.h"
#include
namespace itk
{
template< class TInputImage, class TLabelImage >
bool
ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >
::GetMaskingNonEmpty() const
{
return m_MaskNonEmpty;
}
template< typename TInputImage, typename TLabelImage >
void
ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >
::SetHistogramParameters(const int numBins, RealType lowerBound, RealType upperBound)
{
m_NumBins[0] = numBins;
m_LowerBound = lowerBound;
m_UpperBound = upperBound;
m_GlobalHistogramParametersSet = true;
m_PreferGlobalHistogramParameters = true;
this->Modified();
}
template< typename TInputImage, typename TLabelImage >
void
ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >
::SetHistogramParametersForLabels(std::map numBins, std::map lowerBound,
std::map upperBound)
{
m_LabelMin = lowerBound;
m_LabelMax = upperBound;
m_LabelNBins = numBins;
m_LabelHistogramParametersSet = true;
m_PreferGlobalHistogramParameters = false;
this->Modified();
}
template< class TInputImage, class TLabelImage >
typename ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >::RealType
ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >
::GetUniformity(LabelPixelType label) const
{
StatisticsMapConstIterator mapIt;
mapIt = m_LabelStatistics.find(label);
if ( mapIt == m_LabelStatistics.end() )
{
- // label does not exist, return a default value
- return NumericTraits< PixelType >::Zero;
+ mitkThrow() << "Label does not exist";
}
else
{
return ( *mapIt ).second.m_Uniformity;
}
}
template< class TInputImage, class TLabelImage >
typename ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >::RealType
ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >
::GetMedian(LabelPixelType label) const
{
StatisticsMapConstIterator mapIt;
mapIt = m_LabelStatistics.find(label);
if ( mapIt == m_LabelStatistics.end() )
{
- // label does not exist, return a default value
- return NumericTraits< PixelType >::Zero;
+ mitkThrow() << "Label does not exist";
}
else
{
return ( *mapIt ).second.m_Median;
}
}
template< class TInputImage, class TLabelImage >
typename ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >::RealType
ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >
::GetEntropy(LabelPixelType label) const
{
StatisticsMapConstIterator mapIt;
mapIt = m_LabelStatistics.find(label);
if ( mapIt == m_LabelStatistics.end() )
{
- // label does not exist, return a default value
- return NumericTraits< PixelType >::Zero;
+ mitkThrow() << "Label does not exist";
}
else
{
return ( *mapIt ).second.m_Entropy;
}
}
template< class TInputImage, class TLabelImage >
typename ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >::RealType
ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >
::GetUPP(LabelPixelType label) const
{
StatisticsMapConstIterator mapIt;
mapIt = m_LabelStatistics.find(label);
if ( mapIt == m_LabelStatistics.end() )
{
- // label does not exist, return a default value
- return NumericTraits< PixelType >::Zero;
+ mitkThrow() << "Label does not exist";
}
else
{
return ( *mapIt ).second.m_UPP;
}
}
template< class TInputImage, class TLabelImage >
typename ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >::RealType
ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >
::GetMPP(LabelPixelType label) const
{
StatisticsMapConstIterator mapIt;
mapIt = m_LabelStatistics.find(label);
if ( mapIt == m_LabelStatistics.end() )
{
- // label does not exist, return a default value
- return NumericTraits< PixelType >::Zero;
+ mitkThrow() << "Label does not exist";
}
else
{
return ( *mapIt ).second.m_MPP;
}
}
template< class TInputImage, class TLabelImage >
typename ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >::RealType
ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >
::GetKurtosis(LabelPixelType label) const
{
StatisticsMapConstIterator mapIt;
mapIt = m_LabelStatistics.find(label);
if ( mapIt == m_LabelStatistics.end() )
{
- // label does not exist, return a default value
- return NumericTraits< PixelType >::Zero;
+ mitkThrow() << "Label does not exist";
}
else
{
return ( *mapIt ).second.m_Kurtosis;
}
}
template< class TInputImage, class TLabelImage >
typename ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >::RealType
ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >
::GetSkewness(LabelPixelType label) const
{
StatisticsMapConstIterator mapIt;
mapIt = m_LabelStatistics.find(label);
if ( mapIt == m_LabelStatistics.end() )
{
- // label does not exist, return a default value
- return NumericTraits< PixelType >::Zero;
+ mitkThrow() << "Label does not exist";
}
else
{
return ( *mapIt ).second.m_Skewness;
}
}
template< typename TInputImage, typename TLabelImage >
typename ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >::RealType
ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >
::GetMinimum(LabelPixelType label) const
{
StatisticsMapConstIterator mapIt;
mapIt = m_LabelStatistics.find(label);
if ( mapIt == m_LabelStatistics.end() )
{
- // label does not exist, return a default value
- return NumericTraits< PixelType >::max();
+ mitkThrow() << "Label does not exist";
}
else
{
return ( *mapIt ).second.m_Minimum;
}
}
template< typename TInputImage, typename TLabelImage >
typename ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >::RealType
ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >
::GetMaximum(LabelPixelType label) const
{
StatisticsMapConstIterator mapIt;
mapIt = m_LabelStatistics.find(label);
if ( mapIt == m_LabelStatistics.end() )
{
- // label does not exist, return a default value
- return NumericTraits< PixelType >::NonpositiveMin();
+ mitkThrow() << "Label does not exist";
}
else
{
return ( *mapIt ).second.m_Maximum;
}
}
template< typename TInputImage, typename TLabelImage >
typename ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >::RealType
ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >
::GetMean(LabelPixelType label) const
{
StatisticsMapConstIterator mapIt;
mapIt = m_LabelStatistics.find(label);
if ( mapIt == m_LabelStatistics.end() )
{
- // label does not exist, return a default value
- return NumericTraits< PixelType >::ZeroValue();
+ mitkThrow() << "Label does not exist";
}
else
{
return ( *mapIt ).second.m_Mean;
}
}
template< typename TInputImage, typename TLabelImage >
typename ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >::RealType
ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >
::GetSum(LabelPixelType label) const
{
StatisticsMapConstIterator mapIt;
mapIt = m_LabelStatistics.find(label);
if ( mapIt == m_LabelStatistics.end() )
{
- // label does not exist, return a default value
- return NumericTraits< PixelType >::ZeroValue();
+ mitkThrow() << "Label does not exist";
}
else
{
return ( *mapIt ).second.m_Sum;
}
}
template< typename TInputImage, typename TLabelImage >
typename ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >::RealType
ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >
::GetSigma(LabelPixelType label) const
{
StatisticsMapConstIterator mapIt;
mapIt = m_LabelStatistics.find(label);
if ( mapIt == m_LabelStatistics.end() )
{
- // label does not exist, return a default value
- return NumericTraits< PixelType >::ZeroValue();
+ mitkThrow() << "Label does not exist";
}
else
{
return ( *mapIt ).second.m_Sigma;
}
}
template< typename TInputImage, typename TLabelImage >
typename ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >::RealType
ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >
::GetVariance(LabelPixelType label) const
{
StatisticsMapConstIterator mapIt;
mapIt = m_LabelStatistics.find(label);
if ( mapIt == m_LabelStatistics.end() )
{
- // label does not exist, return a default value
- return NumericTraits< PixelType >::ZeroValue();
+ mitkThrow() << "Label does not exist";
}
else
{
return ( *mapIt ).second.m_Variance;
}
}
template< typename TInputImage, typename TLabelImage >
typename ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >::BoundingBoxType
ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >
::GetBoundingBox(LabelPixelType label) const
{
StatisticsMapConstIterator mapIt;
mapIt = m_LabelStatistics.find(label);
if ( mapIt == m_LabelStatistics.end() )
{
- typename Superclass::BoundingBoxType emptyBox;
- // label does not exist, return a default value
- return emptyBox;
+ mitkThrow() << "Label does not exist";
}
else
{
return ( *mapIt ).second.m_BoundingBox;
}
}
template< typename TInputImage, typename TLabelImage >
typename ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >::RegionType
ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >
::GetRegion(LabelPixelType label) const
{
StatisticsMapConstIterator mapIt;
mapIt = m_LabelStatistics.find(label);
if ( mapIt == m_LabelStatistics.end() )
{
- typename Superclass::RegionType emptyRegion;
- // label does not exist, return a default value
- return emptyRegion;
+ mitkThrow() << "Label does not exist";
}
else
{
typename Superclass::BoundingBoxType bbox = this->GetBoundingBox(label);
typename Superclass::IndexType index;
typename Superclass::SizeType size;
unsigned int dimension = bbox.size() / 2;
for ( unsigned int i = 0; i < dimension; i++ )
{
index[i] = bbox[2 * i];
size[i] = bbox[2 * i + 1] - bbox[2 * i] + 1;
}
typename Superclass::RegionType region;
region.SetSize(size);
region.SetIndex(index);
return region;
}
}
template< typename TInputImage, typename TLabelImage >
typename ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >::MapSizeType
ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >
::GetCount(LabelPixelType label) const
{
StatisticsMapConstIterator mapIt;
mapIt = m_LabelStatistics.find(label);
if ( mapIt == m_LabelStatistics.end() )
{
- // label does not exist, return a default value
- return 0;
+ mitkThrow() << "Label does not exist";
}
else
{
return ( *mapIt ).second.m_Count;
}
}
template< typename TInputImage, typename TLabelImage >
typename ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >::HistogramType::Pointer
ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >
::GetHistogram(LabelPixelType label) const
{
StatisticsMapConstIterator mapIt;
mapIt = m_LabelStatistics.find(label);
if ( mapIt == m_LabelStatistics.end() )
{
- // label does not exist, return a default value
- return ITK_NULLPTR;
+ mitkThrow() << "Label does not exist";
}
else
{
// this will be zero if histograms have not been enabled
return ( *mapIt ).second.m_Histogram;
}
}
template< typename TInputImage, typename TLabelImage >
void
ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >
::BeforeThreadedGenerateData()
{
ThreadIdType numberOfThreads = this->GetNumberOfThreads();
// Resize the thread temporaries
m_LabelStatisticsPerThread.resize(numberOfThreads);
// Initialize the temporaries
for ( ThreadIdType i = 0; i < numberOfThreads; ++i )
{
m_LabelStatisticsPerThread[i].clear();
}
// Initialize the final map
m_LabelStatistics.clear();
}
template< typename TInputImage, typename TLabelImage >
std::list
ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >
::GetRelevantLabels() const
{
std::list< int> relevantLabels;
for (int i = 0; i < 4096; ++i )
{
if ( this->HasLabel( i ) )
{
relevantLabels.push_back( i );
}
}
return relevantLabels;
}
template< typename TInputImage, typename TLabelImage >
void
ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >
::ThreadedGenerateData(const typename TInputImage::RegionType & outputRegionForThread,
ThreadIdType threadId)
{
typename HistogramType::IndexType histogramIndex(1);
typename HistogramType::MeasurementVectorType histogramMeasurement(1);
const SizeValueType size0 = outputRegionForThread.GetSize(0);
if( size0 == 0)
{
return;
}
ImageLinearConstIteratorWithIndex< TInputImage > it (this->GetInput(),
outputRegionForThread);
ImageScanlineConstIterator< TLabelImage > labelIt (this->GetLabelInput(),
outputRegionForThread);
StatisticsMapIterator mapIt;
// support progress methods/callbacks
const size_t numberOfLinesToProcess = outputRegionForThread.GetNumberOfPixels() / size0;
ProgressReporter progress( this, threadId, numberOfLinesToProcess );
typedef typename MapType::value_type MapValueType;
// do the work
while ( !it.IsAtEnd() )
{
while ( !it.IsAtEndOfLine() )
{
const RealType & value = static_cast< RealType >( it.Get() );
const LabelPixelType & label = labelIt.Get();
// is the label already in this thread?
mapIt = m_LabelStatisticsPerThread[threadId].find(label);
if ( mapIt == m_LabelStatisticsPerThread[threadId].end() )
{
// if global histogram parameters are set and preferred then use them
if ( m_PreferGlobalHistogramParameters && m_GlobalHistogramParametersSet )
{
mapIt = m_LabelStatisticsPerThread[threadId].insert( MapValueType( label,
LabelStatistics(m_NumBins[0], m_LowerBound,
m_UpperBound) ) ).first;
}
// if we have label histogram parameters then use them. If we encounter a label that has no parameters then use global settings if available
else if(!m_PreferGlobalHistogramParameters && m_LabelHistogramParametersSet)
{
typename std::map::iterator lbIt, ubIt;
typename std::map::iterator nbIt;
lbIt = m_LabelMin.find(label);
ubIt = m_LabelMax.find(label);
nbIt = m_LabelNBins.find(label);
// if any of the parameters is lacking for the current label but global histogram params are available, use the global parameters
if ((lbIt == m_LabelMin.end() || ubIt == m_LabelMax.end() || nbIt == m_LabelNBins.end()) && m_GlobalHistogramParametersSet)
{
mapIt = m_LabelStatisticsPerThread[threadId].insert( MapValueType( label,
LabelStatistics(m_NumBins[0], m_LowerBound,
m_UpperBound) ) ).first;
}
// if any of the parameters is lacking for the current label and global histogram params are not available, dont use histograms for this label
else if ((lbIt == m_LabelMin.end() || ubIt == m_LabelMax.end() || nbIt == m_LabelNBins.end()) && !m_GlobalHistogramParametersSet)
{
mapIt = m_LabelStatisticsPerThread[threadId].insert( MapValueType( label,
LabelStatistics() ) ).first;
}
// label histogram parameters are available, use them!
else
{
PixelType lowerBound, upperBound;
unsigned int nBins;
lowerBound = (*lbIt).second;
upperBound = (*ubIt).second;
nBins = (*nbIt).second;
mapIt = m_LabelStatisticsPerThread[threadId].insert( MapValueType( label,
LabelStatistics(nBins, lowerBound, upperBound) ) ).first;
}
}
// neither global nor label specific histogram parameters are set -> don't use histograms
else
{
mapIt = m_LabelStatisticsPerThread[threadId].insert( MapValueType( label,
LabelStatistics() ) ).first;
}
}
typename MapType::mapped_type &labelStats = ( *mapIt ).second;
// update the values for this label and this thread
if ( value < labelStats.m_Minimum )
{
labelStats.m_Minimum = value;
}
if ( value > labelStats.m_Maximum )
{
labelStats.m_Maximum = value;
}
// bounding box is min,max pairs
for ( unsigned int i = 0; i < ( 2 * TInputImage::ImageDimension ); i += 2 )
{
const typename TInputImage::IndexType & index = it.GetIndex();
if ( labelStats.m_BoundingBox[i] > index[i / 2] )
{
labelStats.m_BoundingBox[i] = index[i / 2];
}
if ( labelStats.m_BoundingBox[i + 1] < index[i / 2] )
{
labelStats.m_BoundingBox[i + 1] = index[i / 2];
}
}
labelStats.m_Sum += value;
labelStats.m_SumOfSquares += ( value * value );
labelStats.m_Count++;
labelStats.m_SumOfCubes += std::pow(value, 3.);
labelStats.m_SumOfQuadruples += std::pow(value, 4.);
if (value > 0)
{
labelStats.m_PositivePixelCount++;
labelStats.m_SumOfPositivePixels += value;
}
// if enabled, update the histogram for this label
if ( labelStats.m_Histogram.IsNotNull() )
{
histogramMeasurement[0] = value;
labelStats.m_Histogram->GetIndex(histogramMeasurement, histogramIndex);
labelStats.m_Histogram->IncreaseFrequencyOfIndex(histogramIndex, 1);
}
++labelIt;
++it;
}
labelIt.NextLine();
it.NextLine();
progress.CompletedPixel();
}
}
template< class TInputImage, class TLabelImage >
void ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >::
AfterThreadedGenerateData()
{
StatisticsMapIterator mapIt;
StatisticsMapConstIterator threadIt;
ThreadIdType i;
ThreadIdType numberOfThreads = this->GetNumberOfThreads();
// Run through the map for each thread and accumulate the count,
// sum, and sumofsquares
for ( i = 0; i < numberOfThreads; i++ )
{
// iterate over the map for this thread
for ( threadIt = m_LabelStatisticsPerThread[i].begin();
threadIt != m_LabelStatisticsPerThread[i].end();
++threadIt )
{
// does this label exist in the cumulative structure yet?
mapIt = m_LabelStatistics.find( ( *threadIt ).first );
if ( mapIt == m_LabelStatistics.end() )
{
// create a new entry
typedef typename MapType::value_type MapValueType;
if ( m_GlobalHistogramParametersSet || m_LabelHistogramParametersSet )
{
// mapIt = m_LabelStatistics.insert( MapValueType( ( *threadIt ).first,
// LabelStatistics(m_NumBins[0], m_LowerBound,
// m_UpperBound) ) ).first;
mapIt = m_LabelStatistics.insert( MapValueType( *threadIt ) ).first;
continue;
}
else
{
mapIt = m_LabelStatistics.insert( MapValueType( ( *threadIt ).first,
LabelStatistics() ) ).first;
}
}
typename MapType::mapped_type &labelStats = ( *mapIt ).second;
// accumulate the information from this thread
labelStats.m_Count += ( *threadIt ).second.m_Count;
labelStats.m_Sum += ( *threadIt ).second.m_Sum;
labelStats.m_SumOfSquares += ( *threadIt ).second.m_SumOfSquares;
labelStats.m_SumOfPositivePixels += ( *threadIt ).second.m_SumOfPositivePixels;
labelStats.m_PositivePixelCount += ( *threadIt ).second.m_PositivePixelCount;
labelStats.m_SumOfCubes += ( *threadIt ).second.m_SumOfCubes;
labelStats.m_SumOfQuadruples += ( *threadIt ).second.m_SumOfQuadruples;
if ( labelStats.m_Minimum > ( *threadIt ).second.m_Minimum )
{
labelStats.m_Minimum = ( *threadIt ).second.m_Minimum;
}
if ( labelStats.m_Maximum < ( *threadIt ).second.m_Maximum )
{
labelStats.m_Maximum = ( *threadIt ).second.m_Maximum;
}
//bounding box is min,max pairs
int dimension = labelStats.m_BoundingBox.size() / 2;
for ( int ii = 0; ii < ( dimension * 2 ); ii += 2 )
{
if ( labelStats.m_BoundingBox[ii] > ( *threadIt ).second.m_BoundingBox[ii] )
{
labelStats.m_BoundingBox[ii] = ( *threadIt ).second.m_BoundingBox[ii];
}
if ( labelStats.m_BoundingBox[ii + 1] < ( *threadIt ).second.m_BoundingBox[ii + 1] )
{
labelStats.m_BoundingBox[ii + 1] = ( *threadIt ).second.m_BoundingBox[ii + 1];
}
}
// if enabled, update the histogram for this label
if ( m_GlobalHistogramParametersSet || m_LabelHistogramParametersSet )
{
typename HistogramType::IndexType index;
index.SetSize(1);
for ( unsigned int bin = 0; bin < labelStats.m_Histogram->Size(); bin++ )
{
index[0] = bin;
labelStats.m_Histogram->IncreaseFrequency( bin, ( *threadIt ).second.m_Histogram->GetFrequency(bin) );
}
}
} // end of thread map iterator loop
} // end of thread loop
// compute the remainder of the statistics
for ( mapIt = m_LabelStatistics.begin();
mapIt != m_LabelStatistics.end();
++mapIt )
{
typename MapType::mapped_type &labelStats = ( *mapIt ).second;
// mean
labelStats.m_Mean = labelStats.m_Sum
/ static_cast< RealType >( labelStats.m_Count );
// MPP
labelStats.m_MPP = labelStats.m_SumOfPositivePixels
/ static_cast< RealType >( labelStats.m_PositivePixelCount );
// variance
if ( labelStats.m_Count > 0 )
{
// unbiased estimate of variance
LabelStatistics & ls = mapIt->second;
const RealType sumSquared = ls.m_Sum * ls.m_Sum;
const RealType count = static_cast< RealType >( ls.m_Count );
ls.m_Variance = ( ls.m_SumOfSquares - sumSquared / count ) / ( count );
RealType secondMoment = ls.m_SumOfSquares / count;
RealType thirdMoment = ls.m_SumOfCubes / count;
RealType fourthMoment = ls.m_SumOfQuadruples / count;
ls.m_Skewness = (thirdMoment - 3. * secondMoment * ls.m_Mean + 2. * std::pow(ls.m_Mean, 3.)) / std::pow(secondMoment - std::pow(ls.m_Mean, 2.), 1.5); // see http://www.boost.org/doc/libs/1_51_0/doc/html/boost/accumulators/impl/skewness_impl.html
ls.m_Kurtosis = (fourthMoment - 4. * thirdMoment * ls.m_Mean + 6. * secondMoment * std::pow(ls.m_Mean, 2.) - 3. * std::pow(ls.m_Mean, 4.)) / std::pow(secondMoment - std::pow(ls.m_Mean, 2.), 2.); // see http://www.boost.org/doc/libs/1_51_0/doc/html/boost/accumulators/impl/kurtosis_impl.html, dropped -3
}
else
{
labelStats.m_Variance = NumericTraits< RealType >::ZeroValue();
labelStats.m_Skewness = NumericTraits< RealType >::ZeroValue();
labelStats.m_Kurtosis = NumericTraits< RealType >::ZeroValue();
}
// sigma
labelStats.m_Sigma = std::sqrt( labelStats.m_Variance );
// histogram statistics
if (labelStats.m_Histogram.IsNotNull())
{
mitk::HistogramStatisticsCalculator histStatCalc;
histStatCalc.SetHistogram(labelStats.m_Histogram);
histStatCalc.CalculateStatistics();
labelStats.m_Median = histStatCalc.GetMedian();
labelStats.m_Entropy = histStatCalc.GetEntropy();
labelStats.m_Uniformity = histStatCalc.GetUniformity();
labelStats.m_UPP = histStatCalc.GetUPP();
}
}
{
//Now update the cached vector of valid labels.
m_ValidLabelValues.resize(0);
m_ValidLabelValues.reserve(m_LabelStatistics.size());
for ( mapIt = m_LabelStatistics.begin();
mapIt != m_LabelStatistics.end();
++mapIt )
{
m_ValidLabelValues.push_back(mapIt->first);
}
}
}
} // end namespace itk
#endif
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
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-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 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
-
-#include
-
-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(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(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::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 line;
- std::vector 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(this->GetDataNode()->GetProperty("showBoundingBox")) == nullptr)
- showBoundingBox = false;
- else
- showBoundingBox =
- dynamic_cast(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::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
-#include
-#include
-#include
-#include
-#include
-
-#include
-#include
-#include
-
-const mitk::Mesh *mitk::MeshVtkMapper3D::GetInput()
-{
- return static_cast(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(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(this->GetDataNode()->GetProperty("unselectedcolor")) != nullptr)
- {
- tmpColor = dynamic_cast(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(this->GetDataNode()->GetProperty("pointsize"));
- if (pointSizeProp.IsNotNull())
- pointSize = pointSizeProp->GetValue();
-
- for (j = 0, i = itkMesh->GetPoints()->Begin(); i != itkMesh->GetPoints()->End(); i++, j++)
- {
- vtkSmartPointer sphere = vtkSmartPointer::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::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/PhotoacousticsLib/include/mitkPASpectralUnmixingFilterBase.h b/Modules/PhotoacousticsLib/include/mitkPASpectralUnmixingFilterBase.h
index 80fc069e09..dce6a5d2ce 100644
--- a/Modules/PhotoacousticsLib/include/mitkPASpectralUnmixingFilterBase.h
+++ b/Modules/PhotoacousticsLib/include/mitkPASpectralUnmixingFilterBase.h
@@ -1,194 +1,194 @@
/*============================================================================
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 MITKPHOTOACOUSTICSPECTRALUNMIXINGFILTERBASE_H
#define MITKPHOTOACOUSTICSPECTRALUNMIXINGFILTERBASE_H
#include "mitkImageToImageFilter.h"
#include
//Includes for smart pointer usage
#include "mitkCommon.h"
#include "itkLightObject.h"
// Includes for AddEnmemberMatrix
#include "mitkPAPropertyCalculator.h"
#include
namespace mitk {
namespace pa {
/**
* \brief The spectral unmixing filter base is designed as superclass for several spectral unmixing filter eg. Eigen- or Vigrabased ones.
* One can add wavelengths and chromophores and get a unmixed output images out of one MITK input image using algorithms from the subclasses.
*
* Input:
* The unmixing input has to be a 3D MITK image where the XY-plane is a image and the Z-direction represents recordings for different
* wavelengths. Herein a XY-plane for a specific Z-direction will be called "image". Every image has to be assigned to a certain wavelength.
* The "AddWavelength" uses "push_back" to write float values into a vector. The first wavelength will correspond to the first image!!!
* If there a more input images 'I' then added wavelengths 'w' the filter base interprets the next x images as repetition sequence of the same
* wavelengths. If I % w !=0 the surplus image(s) will be dropped.
* Addtionaly one has to add chromophores from the property calculator class enum "ChromophoreType" with the "AddChromophore" method.
* This method as well uses "push_back" but the chosen (arbitary) order will be the order of the outputs.
*
* Output:
* The output will be one MITK image per chosen chromophore. Where the XY-plane is a image and the Z-direction represents recordings for different
* sequences. Furthermore it is possible to creat an output image that contains the information about the relative error between unmixing result
* and the input image.
*
* Subclasses:
* - mitkPASpectralUnmixingFilterVigra
* - mitkPALinearSpectralUnmixingFilter (uses Eigen algorithms)
* - mitkPASpectralUnmixingFilterSimplex
*
* Possible exceptions:
* - "PIXELTYPE ERROR! FLOAT 32 REQUIRED": The MITK input image has to consist out of floats.
* - "ERROR! REMOVE WAVELENGTHS!": One needs at least the same amount of images (z-dimension) then added wavelengths.
* - "ADD MORE WAVELENGTHS!": One needs at least the same amount of wavelengths then added chromophores.
* - "WAVELENGTH XXX nm NOT SUPPORTED!": The wavelength is not part of the proptery calculater data base. The data base can be found @
* [...]/mitk/Modules/PhotoacousticsLib/Resources/spectralLIB.dat
* - "ADD OUTPUTS HAS TO BE LARGER THEN ZERO!"
* - "NO WAVELENGHTS/CHROMOPHORES SELECZED!
* - "INDEX ERROR! NUMBER OF OUTPUTS DOESN'T FIT TO OTHER SETTIGNS!"
*/
class MITKPHOTOACOUSTICSLIB_EXPORT SpectralUnmixingFilterBase : public mitk::ImageToImageFilter
{
public:
mitkClassMacro(SpectralUnmixingFilterBase, mitk::ImageToImageFilter);
/**
* \brief AddChromophore takes mitk::pa::PropertyCalculator::ChromophoreType and writes them at the end of the m_Chromophore vector.
* The call of the method sets the order of the GetOutput method!
*
* @param chromophore has to be element of porperty calculater enum chromophore type
* @return for wavelength smaller then 300nm and larger then 1000nm the return will be 0, because not at the data base (2018/06/19)
*/
void AddChromophore(mitk::pa::PropertyCalculator::ChromophoreType chromophore);
/**
* \brief AddWavelength takes integers and writes them at the end of the m_Wavelength vector. The first call of the method then
* corresponds to the first input image and so on.
* @param wavelength database supports integers between 300 and 1000 nm
*/
void AddWavelength(int wavelength);
/*
* \brief Verbose gives more information to the console. Default value is false.
* @param verbose is the boolian to activate the MITK_INFO logged to the console
*/
virtual void Verbose(bool verbose);
/**
* \brief AddOutputs takes an integer and sets indexed outputs
* @param outputs integer correponds to the number of output images
* @throws if outputs == 0
*/
virtual void AddOutputs(unsigned int outputs);
/*
* \brief RelativeError returns a image which compare the L2 norm of the input vector with the unmixing result
* @param relativeError is the boolian to activate this tool
*/
virtual void RelativeError(bool relativeError);
/**
* \brief AddRelativeErrorSettings takes integers and writes them at the end of the m_RelativeErrorSettings vector.
* @param value has to be a integer
*/
virtual void AddRelativeErrorSettings(int value);
- ofstream myfile; // just for testing purposes; has to be removeed
+ std::ofstream myfile; // just for testing purposes; has to be removeed
protected:
/**
* \brief Constructor creats proptery calculater smart pointer new()
*/
SpectralUnmixingFilterBase();
~SpectralUnmixingFilterBase() override;
/**
* \brief The subclasses will override the mehtod to calculate the spectral unmixing result vector.
* @param endmemberMatrix Matrix with number of chromophores colums and number of wavelengths rows so matrix element (i,j) contains
* the absorbtion of chromophore j @ wavelength i taken from the database by PropertyElement method.
* @param inputVector Vector containing values of one pixel of XY-plane image with number of wavelength rows (z-dimension of a sequenece)
* so the pixelvalue of the first wavelength is stored in inputVector[0] and so on.
* @throws if algorithm implementiation fails (implemented for the algorithms with critical requirements)
*/
virtual Eigen::VectorXf SpectralUnmixingAlgorithm(Eigen::Matrix endmemberMatrix,
Eigen::VectorXf inputVector) = 0;
bool m_Verbose = false;
bool m_RelativeError = false;
std::vector m_Chromophore;
std::vector m_Wavelength;
std::vector m_RelativeErrorSettings;
private:
/*
* \brief Initialized output images with the same XY-plane size like the input image and total size in z-direction equals number of sequences.
* The pixel type is set to float.
* @param totalNumberOfSequences = (unsigned int) (numberOfInputImages / numberOfWavelength) >= 1
*/
virtual void InitializeOutputs(unsigned int totalNumberOfSequences);
/*
* \brief Checks if there are a suitable amount of wavelengths and if the input image consists of floats.
* @param input pointer on the MITK input image
* @throws if there are more wavelength then images
* @throws if there are more chromophores then wavelengths
* @throws if the pixel type is not float 32
* @throws if no chromophores or wavelengths selected as input
* @throws if the number of indexed outputs does'nt fit to the expected number
*/
virtual void CheckPreConditions(mitk::Image::Pointer input);
/*
* \brief Inherit from the "ImageToImageFilter" Superclass. Herain it calls InitializeOutputs, CalculateEndmemberMatrix and
* CheckPreConditions methods and enables pixelwise access to do spectral unmixing with the "SpectralUnmixingAlgorithm"
* method. In the end the method writes the results into the new MITK output images.
*/
void GenerateData() override;
/*
* \brief Creats a Matrix with number of chromophores colums and number of wavelengths rows so matrix element (i,j) contains
* the absorbtion of chromophore j @ wavelength i. The absorbtion values are taken from the "PropertyElement" method.
* @param m_Chromophore is a vector of "PropertyCalculator::ChromophoreType" containing all selected chromophores for the unmixing
* @param m_Wavelength is a vector of integers containing all wavelengths of one sequence
*/
virtual Eigen::Matrix CalculateEndmemberMatrix(
std::vector m_Chromophore, std::vector m_Wavelength);
/*
* \brief "PropertyElement" is the tool to access the absorbtion values out of the database using mitk::pa::PropertyCalculator::GetAbsorptionForWavelengt
* and checks if the requested wavelength is part of the database (not zero values). The "ONEENDMEMBER" is a pseudo absorber with static absorbtion 1
* at every wavelength and is therefor not part of the database. If this one is the selected chromophore the return value is 1 for every wavelength.
* @param wavelength has to be integer between 300 and 1000 nm
* @param chromophore has to be a mitk::pa::PropertyCalculator::ChromophoreType
* @throws if mitk::pa::PropertyCalculator::GetAbsorptionForWavelengt returns 0, because this means that the delivered wavelength is not in the database.
*/
virtual float PropertyElement(mitk::pa::PropertyCalculator::ChromophoreType, int wavelength);
/*
* \brief calculates the relative error between the input image and the unmixing result in the L2 norm
* @param endmemberMatrix is a Eigen matrix containing the endmember information
* @param inputVector is a Eigen vector containing the multispectral information of one pixel
* @param resultVector is a Eigen vector containing the spectral unmmixing result
*/
float CalculateRelativeError(Eigen::Matrix endmemberMatrix,
Eigen::VectorXf inputVector, Eigen::VectorXf resultVector);
PropertyCalculator::Pointer m_PropertyCalculatorEigen;
};
}
}
#endif // MITKPHOTOACOUSTICSPECTRALUNMIXINGFILTERBASE_
diff --git a/Modules/Remeshing/CMakeLists.txt b/Modules/Remeshing/CMakeLists.txt
index 177531d9fe..2697e18603 100644
--- a/Modules/Remeshing/CMakeLists.txt
+++ b/Modules/Remeshing/CMakeLists.txt
@@ -1,7 +1,9 @@
mitk_create_module(
- DEPENDS MitkCore
- PACKAGE_DEPENDS ACVD VTK|IOPLY+IOMINC
- )
-
-add_subdirectory(Testing)
+ DEPENDS MitkCore
+ PACKAGE_DEPENDS OpenMesh|OpenMeshTools
+)
+if(TARGET ${MODULE_TARGET})
+ target_link_libraries(${MODULE_TARGET} PRIVATE OpenMeshTools)
+ target_compile_definitions(${MODULE_TARGET} PRIVATE -D_USE_MATH_DEFINES)
+endif()
diff --git a/Modules/Remeshing/Testing/CMakeLists.txt b/Modules/Remeshing/Testing/CMakeLists.txt
deleted file mode 100644
index a29ccbc947..0000000000
--- a/Modules/Remeshing/Testing/CMakeLists.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-if(MITK_USE_ACVD)
- MITK_CREATE_MODULE_TESTS()
-
- mitkAddCustomModuleTest(mitkACVDTest mitkACVDTest ${MITK_DATA_DIR}/binary.stl 0 1228 1.0 10 0.0 1 0 0)
-endif()
diff --git a/Modules/Remeshing/Testing/files.cmake b/Modules/Remeshing/Testing/files.cmake
deleted file mode 100644
index 055665bf46..0000000000
--- a/Modules/Remeshing/Testing/files.cmake
+++ /dev/null
@@ -1,6 +0,0 @@
-set(MODULE_TESTS
-)
-
-set(MODULE_CUSTOM_TESTS
- mitkACVDTest.cpp
-)
diff --git a/Modules/Remeshing/Testing/mitkACVDTest.cpp b/Modules/Remeshing/Testing/mitkACVDTest.cpp
deleted file mode 100644
index f5bf8d5364..0000000000
--- a/Modules/Remeshing/Testing/mitkACVDTest.cpp
+++ /dev/null
@@ -1,138 +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
-#include
-#include
-#include
-#include
-#include
-#include
-
-#define _MITK_TEST_FOR_EXCEPTION(STATEMENT, EXCEPTION, MESSAGE) \
- MITK_TEST_OUTPUT_NO_ENDL(<< MESSAGE) \
- try \
- { \
- STATEMENT; \
- MITK_TEST_OUTPUT(<< " [FAILED]") \
- mitk::TestManager::GetInstance()->TestFailed(); \
- } \
- catch (const EXCEPTION &e) \
- { \
- MITK_TEST_OUTPUT(<< "\n " << e.GetDescription() << " [PASSED]") \
- mitk::TestManager::GetInstance()->TestPassed(); \
- }
-
-template
-static T lexical_cast(const std::string &string)
-{
- std::istringstream sstream(string);
- T value;
-
- sstream >> value;
-
- if (sstream.fail())
- {
- MITK_ERROR << "Lexical cast failed for '" << string << "'!";
- exit(EXIT_FAILURE);
- }
-
- return value;
-}
-
-static void Remesh_SurfaceIsNull_ThrowsException()
-{
- mitk::Surface::ConstPointer surface;
- _MITK_TEST_FOR_EXCEPTION(
- mitk::ACVD::Remesh(surface, 0, 100, 0.0), mitk::Exception, "Remesh_SurfaceIsNull_ThrowsException")
-}
-
-static void Remesh_PolyDataIsNull_ThrowsException()
-{
- mitk::Surface::ConstPointer surface = mitk::Surface::New().GetPointer();
- _MITK_TEST_FOR_EXCEPTION(
- mitk::ACVD::Remesh(surface, 0, 100, 0.0), mitk::Exception, "Remesh_PolyDataIsNull_ThrowsException")
-}
-
-static void Remesh_SurfaceDoesNotHaveDataAtTimeStep_ThrowsException()
-{
- mitk::Surface::ConstPointer surface = mitk::Surface::New().GetPointer();
- _MITK_TEST_FOR_EXCEPTION(mitk::ACVD::Remesh(surface, 1, 100, 0.0),
- mitk::Exception,
- "Remesh_SurfaceDoesNotHaveDataAtTimeStep_ThrowsException")
-}
-
-static void Remesh_SurfaceHasNoPolygons_ThrowsException()
-{
- mitk::Surface::Pointer surface = mitk::Surface::New();
- vtkSmartPointer polyData = vtkSmartPointer::New();
- surface->SetVtkPolyData(polyData);
- _MITK_TEST_FOR_EXCEPTION(mitk::ACVD::Remesh(surface.GetPointer(), 0, 100, 0.0),
- mitk::Exception,
- "Remesh_SurfaceHasNoPolygons_ThrowsException")
-}
-
-static void Remesh_SurfaceIsValid_ReturnsRemeshedSurface(const std::string &filename,
- unsigned int t,
- int numVertices,
- double gradation,
- int subsampling,
- double edgeSplitting,
- int optimizationLevel,
- bool forceManifold,
- bool boundaryFixing)
-{
- auto surface = mitk::IOUtil::Load(filename);
- mitk::Surface::Pointer remeshedSurface = mitk::ACVD::Remesh(
- surface.GetPointer(), t, numVertices, gradation, subsampling, edgeSplitting, optimizationLevel, forceManifold, boundaryFixing);
- MITK_TEST_CONDITION(remeshedSurface.IsNotNull() && remeshedSurface->GetVtkPolyData() != nullptr &&
- remeshedSurface->GetVtkPolyData()->GetNumberOfPolys() != 0,
- "Remesh_SurfaceIsValid_ReturnsRemeshedSurface")
-}
-
-int mitkACVDTest(int argc, char *argv[])
-{
- if (argc != 10)
- {
- MITK_ERROR << "Invalid argument count!\n"
- << "Usage: mitkACVDTest