diff --git a/Core/Code/Rendering/mitkPointSetVtkMapper2D.cpp b/Core/Code/Rendering/mitkPointSetVtkMapper2D.cpp index 5d4259bea8..60a17c0e62 100644 --- a/Core/Code/Rendering/mitkPointSetVtkMapper2D.cpp +++ b/Core/Code/Rendering/mitkPointSetVtkMapper2D.cpp @@ -1,576 +1,731 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkPointSetVtkMapper2D.h" #include "mitkDataNode.h" #include "mitkProperties.h" #include "mitkColorProperty.h" #include "mitkEnumerationProperty.h" #include "mitkVtkPropRenderer.h" #include "mitkPointSet.h" #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 #include #include #include #include #include const mitk::PointSet* mitk::PointSetVtkMapper2D::GetInput() { return static_cast ( GetDataNode()->GetData() ); } mitk::PointSetVtkMapper2D::PointSetVtkMapper2D() : m_Polygon(false), m_PolygonClosed(false), m_ShowPoints(true), m_ShowDistances(false), m_DistancesDecimalDigits(1), m_ShowAngles(false), m_ShowDistantLines(false), m_LineWidth(1), m_PointLineWidth(1), m_Point2DSize(2), m_IdGlyph(3), // default: cross m_FillGlyphs(false) { } mitk::PointSetVtkMapper2D::~PointSetVtkMapper2D() { } void mitk::PointSetVtkMapper2D::ResetMapper( BaseRenderer* renderer ) { LocalStorage *ls = m_LSH.GetLocalStorage(renderer); ls->m_PropAssemblies->VisibilityOff(); } vtkProp* mitk::PointSetVtkMapper2D::GetVtkProp(mitk::BaseRenderer * renderer) { LocalStorage *ls = m_LSH.GetLocalStorage(renderer); return ls->m_PropAssemblies; } /* void mitk::PointSetVtkMapper2D::ReleaseGraphicsResources(vtkWindow *renWin) { LocalStorage *ls = m_LSH.GetLocalStorage(renderer); ls-> m_PointsAssembly->ReleaseGraphicsResources(renWin); ls->m_SelectedActor->ReleaseGraphicsResources(renWin); ls->m_UnselectedActor->ReleaseGraphicsResources(renWin); ls->m_ContourActor->ReleaseGraphicsResources(renWin); } */ +static bool makePerpendicularVector2D(const mitk::Vector2D& in, mitk::Vector2D& out) +{ + if((fabs(in[0])>0) && ( (fabs(in[0])>fabs(in[1])) || (in[1] == 0) ) ) + { + out[0]=-in[1]/in[0]; + out[1]=1; + out.Normalize(); + return true; + } + else + if(fabs(in[1])>0) + { + out[0]=1; + out[1]=-in[0]/in[1]; + out.Normalize(); + return true; + } + else + return false; +} + void mitk::PointSetVtkMapper2D::CreateVTKRenderObjects(mitk::BaseRenderer* renderer) { LocalStorage *ls = m_LSH.GetLocalStorage(renderer); if(ls->m_PropAssemblies->GetParts()->IsItemPresent(ls->m_UnselectedActors)) ls->m_PropAssemblies->RemovePart(ls->m_UnselectedActors); if(ls->m_PropAssemblies->GetParts()->IsItemPresent(ls->m_SelectedActors)) ls->m_PropAssemblies->RemovePart(ls->m_SelectedActors); if(ls->m_PropAssemblies->GetParts()->IsItemPresent(ls->m_ContourActors)) ls->m_PropAssemblies->RemovePart(ls->m_ContourActors); // exceptional displaying for PositionTracker -> MouseOrientationTool int mapperID; bool isInputDevice=false; if( this->GetDataNode()->GetBoolProperty("inputdevice",isInputDevice) && isInputDevice ) { if( this->GetDataNode()->GetIntProperty("BaseRendererMapperID",mapperID) && mapperID == 2) return; //The event for the PositionTracker came from the 3d widget and not needs to be displayed } // get input point set and update the PointSet mitk::PointSet::Pointer input = const_cast(this->GetInput()); /* only update the input data, if the property tells us to */ bool update = true; this->GetDataNode()->GetBoolProperty("updateDataOnRender", update); if (update == true) input->Update(); int timestep = this->GetTimestep(); mitk::PointSet::DataType::Pointer itkPointSet = input->GetPointSet( timestep ); if ( itkPointSet.GetPointer() == NULL) { ls->m_PropAssemblies->VisibilityOff(); return; } mitk::PointSet::PointsContainer::Iterator pointsIter; mitk::PointSet::PointsContainer::Iterator pointsIterPredecessor; pointsIterPredecessor = itkPointSet->GetPoints()->Begin(); // PointDataContainer has additional information to each point, e.g. whether // it is selected or not mitk::PointSet::PointDataContainer::Iterator pointDataIter; pointDataIter = itkPointSet->GetPointData()->Begin(); //check if the list for the PointDataContainer is the same size as the PointsContainer. //If not, then the points were inserted manually and can not be visualized according to the PointData (selected/unselected) bool pointDataBroken = (itkPointSet->GetPointData()->Size() != itkPointSet->GetPoints()->Size()); if(itkPointSet->GetPointData()->size() == 0 || pointDataBroken) { return; } // current point in point set itk::Point point; itk::Point pointPredecessor; // reset the point sets ls->m_UnselectedPoints->Reset(); ls->m_SelectedPoints->Reset(); ls->m_ContourPoints->Reset(); ls->m_UnselectedScales->Reset(); ls->m_SelectedScales->Reset(); + ls->m_DistancesBetweenPoints->Reset(); + ls->m_UnselectedScales->SetNumberOfComponents(3); ls->m_SelectedScales->SetNumberOfComponents(3); int NumberOfSelectedPoints = 0; int NumberOfUnselectedPoints = 0; int NumberOfContourPoints = 0; + const int text2dDistance = 10; + bool pointInArray = false; bool pointsOnSameSideOfPlane = false; + Point3D p; // currently visited point + Point3D lastP; // last visited point + Vector3D vec; // p - lastP + Vector3D lastVec; // lastP - point before lastP + vec.Fill(0); + + mitk::Point3D projected_p; // p projected on viewplane + + Point2D pt2d; // projected_p in display coordinates + Point2D lastPt2d; // last projected_p in display coordinates + Point2D preLastPt2d;// projected_p in display coordinates before lastPt2d + + mitk::DisplayGeometry::Pointer displayGeometry = renderer->GetDisplayGeometry(); // get plane geometry mitk::PlaneGeometry::ConstPointer planeGeo = renderer->GetSliceNavigationController()->GetCurrentPlaneGeometry(); for (pointsIter=itkPointSet->GetPoints()->Begin(); pointsIter!=itkPointSet->GetPoints()->End(); pointsIter++) { if( pointsIter != itkPointSet->GetPoints()->Begin()) { pointsIterPredecessor = pointsIter; pointsIterPredecessor--; } // get current point in point set point = pointsIter->Value(); + p[0] = point[0]; + p[1] = point[1]; + p[2] = point[2]; // compute distance to current plane float diff = planeGeo->DistanceFromPlane(point); // point is close to current plane if(diff < 4.0) { // is point selected or not? if (pointDataIter->Value().selected) { ls->m_SelectedPoints->InsertPoint(NumberOfSelectedPoints,point[0],point[1],point[2]); // point is scaled according to its distance to the plane ls->m_SelectedScales->InsertNextTuple3(m_Point2DSize + (2/diff),0,0); NumberOfSelectedPoints++; } else { ls->m_UnselectedPoints->InsertPoint(NumberOfUnselectedPoints,point[0],point[1],point[2]); // point is scaled according to its distance to the plane ls->m_UnselectedScales->InsertNextTuple3(m_Point2DSize + (2/diff),0,0); NumberOfUnselectedPoints++; } } // add points that are needed for the contour if( (pointsIter != itkPointSet->GetPoints()->Begin()) ) { pointPredecessor = pointsIterPredecessor->Value(); ScalarType distance = displayGeometry->GetWorldGeometry()->SignedDistance(point); ScalarType lastDistance = displayGeometry->GetWorldGeometry()->SignedDistance(pointPredecessor); pointsOnSameSideOfPlane = (distance * lastDistance) > 0.5; - if ( !pointsOnSameSideOfPlane ) // points on different sides of plane + if ( !pointsOnSameSideOfPlane ) // points on different sides of plane -> draw it { + + float distancePoints = point.EuclideanDistanceTo(pointPredecessor); + + if(!pointInArray) { ls->m_ContourPoints->InsertPoint(NumberOfContourPoints, pointPredecessor[0],pointPredecessor[1],pointPredecessor[2]); NumberOfContourPoints++; + // ls->m_DistancesBetweenPoints->InsertComponent(-4.0f); } ls->m_ContourPoints->InsertPoint(NumberOfContourPoints, point[0],point[1],point[2]); NumberOfContourPoints++; + //ls->m_DistancesBetweenPoints->InsertPoint(distancePoints); pointInArray = true; + + + + if(m_ShowDistances) // calculate and print a distance + { + + displayGeometry->Project(p, projected_p); + displayGeometry->Map(projected_p, pt2d); + displayGeometry->WorldToDisplay(pt2d, pt2d); + + std::stringstream buffer; + //float distance = vec.GetNorm(); + buffer<( renderer ); + propRenderer->WriteSimpleText(buffer.str(), pos2d[0], pos2d[1]); + //this->WriteTextXY(pos2d[0], pos2d[1], buffer.str(),renderer); + } + + } else { pointInArray = false; } } if(pointDataIter != itkPointSet->GetPointData()->End()) { pointDataIter++; } } //create lines between the points which are close to the plane if (m_Polygon) { // insert first point again if contour should be closed if(m_PolygonClosed){ pointsIter=itkPointSet->GetPoints()->Begin(); // get current point in point set point = pointsIter->Value(); ls->m_ContourPoints->InsertPoint(NumberOfContourPoints,point[0],point[1],point[2]); NumberOfContourPoints++; } int NumberOfPoints = ls->m_ContourPoints->GetNumberOfPoints(); vtkSmartPointer polyLine = vtkSmartPointer::New(); polyLine->GetPointIds()->SetNumberOfIds(NumberOfPoints); for(unsigned int i=0; i< NumberOfPoints; i++) { polyLine->GetPointIds()->SetId(i,i); } vtkSmartPointer cells = vtkSmartPointer::New(); cells->InsertNextCell(polyLine); ls->m_VtkContourPolyData->SetPoints(ls->m_ContourPoints); ls->m_VtkContourPolyData->SetLines(cells); ls->m_VtkContourPolyDataMappers->SetInput(ls->m_VtkContourPolyData); ls->m_ContourActors->SetMapper(ls->m_VtkContourPolyDataMappers); ls->m_ContourActors->GetProperty()->SetLineWidth(m_LineWidth); ls->m_PropAssemblies->AddPart(ls->m_ContourActors); } // create label if(m_ShowDistances) + // { + /*vtkSmartPointer label; + vtkSmartPointer aLabelTransform; + vtkSmartPointer labelTransform; + + for (pointsIter=itkPointSet->GetPoints()->Begin(); + pointsIter!=itkPointSet->GetPoints()->End(); + pointsIter++) { - // Setup the text and add it to the window - // vtkSmartPointer textActor = vtkSmartPointer::New(); - // textActor->GetTextProperty()->SetFontSize ( 24 ); - // textActor->SetPosition2 ( 10, 40 ); - // ls->m_PropAssemblies->AddPart(textActor); - //// renderer->AddActor2D ( textActor ); - // textActor->SetInput ( "Hello world" ); - // textActor->GetTextProperty()->SetColor ( 1.0,0.0,0.0 ); - } + // todo label nur auf den punkten die angezeigt werden + + // char buffer[20]; + // std::string l = pointLabel; + std::string l = "baeh"; + //if ( input->GetSize()>1 ) + //{ + // sprintf(buffer,"%d",j+1); + // l.append(buffer); + //} + // Define the text for the label + label = vtkSmartPointer::New(); + label->SetText(l.c_str()); + + //# Set up a transform to move the label to a new position. + aLabelTransform = vtkSmartPointer::New(); + aLabelTransform->Identity(); + itk::Point point1 = pointsIter->Value(); + aLabelTransform->Translate(point1[0]+2,point1[1]+2,point1[2]); + aLabelTransform->Scale(5.7,5.7,5.7); + + //# Move the label to a new position. + + labelTransform = vtkSmartPointer::New(); + labelTransform->SetTransform(aLabelTransform); + labelTransform->SetInput(label->GetOutput()); + + ls->m_VtkTextPolyData->AddInput(labelTransform->GetOutput()); +} + }*/ + + + + + + + + +// show label + + const int text2dDistance = 10; + // now paint text if available + + for (pointsIter=itkPointSet->GetPoints()->Begin(); + pointsIter!=itkPointSet->GetPoints()->End(); + pointsIter++){ + + // displayGeometry->Map(projected_p, pt2d); + // displayGeometry->WorldToDisplay(pt2d, pt2d); + + point = pointsIter->Value(); + if (dynamic_cast(this->GetDataNode() + ->GetProperty("label")) != NULL) + { + const char * pointLabel = dynamic_cast( + this->GetDataNode()->GetProperty("label"))->GetValue(); + std::string l = pointLabel; + if (input->GetSize()>1) + { + // char buffer[20]; + // sprintf(buffer,"%d",it->Index()); + std::stringstream ss; + ss << pointsIter->Index(); + l.append(ss.str()); + } + //if (unselectedColor != NULL) + // { + //mitk::VtkPropRenderer* OpenGLrenderer = dynamic_cast( renderer ); + // float rgb[3];//yellow + // rgb[0] = unselectedColor[0]; rgb[1] = unselectedColor[1]; rgb[2] = unselectedColor[2]; + // renderer->WriteSimpleText(l, point[0] + text2dDistance, point[1] + text2dDistance,rgb[0], rgb[1],rgb[2]); + // } + // else + // { + mitk::VtkPropRenderer* propRenderer = dynamic_cast( renderer ); + propRenderer->WriteSimpleText(l, point[0] + text2dDistance, point[1] + text2dDistance,0.0,1.0,0.0); + // } + } + } + + ls->m_VtkTextPolyDataMapper->SetInput(ls->m_VtkTextPolyData->GetOutput()); + ls->m_VtkTextActor->SetMapper(ls->m_VtkTextPolyDataMapper); + + ls->m_PropAssemblies->AddPart(ls->m_VtkTextActor); // the point set must be transformed in order to obtain the appropriate glyph orientation // according to the current view vtkSmartPointer transform = vtkSmartPointer::New(); vtkSmartPointer a,b = vtkSmartPointer::New(); a = planeGeo->GetVtkTransform()->GetMatrix(); b->DeepCopy( a ); // delete transformation from matrix, only take orientation b->SetElement(3,3,1); b->SetElement(2,3,0); b->SetElement(1,3,0); b->SetElement(0,3,0); b->SetElement(3,2,0); b->SetElement(3,1,0); b->SetElement(3,0,0); transform->SetMatrix( b ); //---- UNSELECTED POINTS -----// // apply properties to glyph ls->m_UnselectedGlyphSource2D->SetGlyphType(m_IdGlyph); if(m_FillGlyphs) ls->m_UnselectedGlyphSource2D->FilledOn(); else ls->m_UnselectedGlyphSource2D->FilledOff(); // apply transform vtkSmartPointer transformFilterU = vtkSmartPointer::New(); transformFilterU->SetInputConnection(ls->m_UnselectedGlyphSource2D->GetOutputPort()); transformFilterU->SetTransform(transform); ls->m_VtkUnselectedPointListPolyData->SetPoints(ls->m_UnselectedPoints); ls->m_VtkUnselectedPointListPolyData->GetPointData()->SetVectors(ls->m_UnselectedScales); // apply transform of current plane to glyphs ls->m_UnselectedGlyph3D->SetSourceConnection(transformFilterU->GetOutputPort()); ls->m_UnselectedGlyph3D->SetInput(ls->m_VtkUnselectedPointListPolyData); ls->m_UnselectedGlyph3D->SetScaleModeToScaleByVector(); ls->m_UnselectedGlyph3D->SetVectorModeToUseVector(); ls->m_VtkUnselectedPolyDataMappers->SetInput(ls->m_UnselectedGlyph3D->GetOutput()); ls->m_UnselectedActors->SetMapper(ls->m_VtkUnselectedPolyDataMappers); ls->m_PropAssemblies->AddPart(ls->m_UnselectedActors); //---- SELECTED POINTS -----// ls->m_SelectedGlyphSource2D->SetGlyphTypeToDiamond(); ls->m_SelectedGlyphSource2D->FilledOff(); // apply transform vtkSmartPointer transformFilterS = vtkSmartPointer::New(); transformFilterS->SetInputConnection(ls->m_SelectedGlyphSource2D->GetOutputPort()); transformFilterS->SetTransform(transform); ls->m_VtkSelectedPointListPolyData->SetPoints(ls->m_SelectedPoints); ls->m_VtkSelectedPointListPolyData->GetPointData()->SetVectors(ls->m_SelectedScales); // apply transform of current plane to glyphs ls->m_SelectedGlyph3D->SetSourceConnection(transformFilterS->GetOutputPort()); ls->m_SelectedGlyph3D->SetInput(ls->m_VtkSelectedPointListPolyData); ls->m_SelectedGlyph3D->SetScaleModeToScaleByVector(); ls->m_SelectedGlyph3D->SetVectorModeToUseVector(); ls->m_VtkSelectedPolyDataMappers->SetInput(ls->m_SelectedGlyph3D->GetOutput()); ls->m_SelectedActors->SetMapper(ls->m_VtkSelectedPolyDataMappers); ls->m_PropAssemblies->AddPart(ls->m_SelectedActors); } void mitk::PointSetVtkMapper2D::GenerateDataForRenderer( mitk::BaseRenderer *renderer ) { const mitk::DataNode* node = GetDataNode(); if( node == NULL ) return; LocalStorage *ls = m_LSH.GetLocalStorage(renderer); // toggle visibility bool visible = true; node->GetVisibility(visible, renderer, "visible"); if(!visible) { ls->m_UnselectedActors->VisibilityOff(); ls->m_SelectedActors->VisibilityOff(); ls->m_ContourActors->VisibilityOff(); ls->m_PropAssemblies->VisibilityOff(); return; }else{ ls->m_PropAssemblies->VisibilityOn(); } node->GetBoolProperty("show contour", m_Polygon, renderer); node->GetBoolProperty("close contour", m_PolygonClosed, renderer); node->GetBoolProperty("show points", m_ShowPoints, renderer); node->GetBoolProperty("show distances", m_ShowDistances, renderer); node->GetIntProperty("distance decimal digits", m_DistancesDecimalDigits, renderer); node->GetBoolProperty("show angles", m_ShowAngles, renderer); node->GetBoolProperty("show distant lines", m_ShowDistantLines, renderer); node->GetIntProperty("line width", m_LineWidth, renderer); node->GetIntProperty("point line width", m_PointLineWidth, renderer); node->GetIntProperty("point 2D size", m_Point2DSize, renderer); mitk::EnumerationProperty* eP = dynamic_cast (node->GetProperty("glyph type", renderer)); m_IdGlyph = eP->GetValueAsId(); node->GetBoolProperty("fill glyphs", m_FillGlyphs, renderer); //check for color props and use it for rendering of selected/unselected points and contour //due to different params in VTK (double/float) we have to convert! float unselectedColor[4]; vtkFloatingPointType selectedColor[4]={1.0f,0.0f,0.0f,1.0f}; //red vtkFloatingPointType contourColor[4]={1.0f,0.0f,0.0f,1.0f}; //red //different types for color mitk::Color tmpColor; float opacity = 1.0; GetDataNode()->GetOpacity(opacity, renderer); // apply color and opacity if(m_ShowPoints) { ls->m_UnselectedActors->VisibilityOn(); ls->m_SelectedActors->VisibilityOn(); // ApplyAllProperties(renderer, ls->m_UnselectedActors); // ApplyAllProperties(renderer, ls->m_SelectedActors); //check if there is a color property GetDataNode()->GetColor(unselectedColor); //get selected color property if (dynamic_cast(this->GetDataNode()->GetPropertyList(renderer)->GetProperty("selectedcolor")) != NULL) { tmpColor = dynamic_cast(this->GetDataNode()->GetPropertyList(renderer)->GetProperty("selectedcolor"))->GetValue(); } else if (dynamic_cast(this->GetDataNode()->GetPropertyList(NULL)->GetProperty("selectedcolor")) != NULL) { tmpColor = dynamic_cast(this->GetDataNode()->GetPropertyList(NULL)->GetProperty("selectedcolor"))->GetValue(); } selectedColor[0] = tmpColor[0]; selectedColor[1] = tmpColor[1]; selectedColor[2] = tmpColor[2]; selectedColor[3] = 1.0f; // alpha value ls->m_SelectedActors->GetProperty()->SetColor(selectedColor); ls->m_SelectedActors->GetProperty()->SetOpacity(opacity); ls->m_UnselectedActors->GetProperty()->SetColor(unselectedColor[0],unselectedColor[1],unselectedColor[2]); ls->m_UnselectedActors->GetProperty()->SetOpacity(opacity); } else { ls->m_UnselectedActors->VisibilityOff(); ls-> m_SelectedActors->VisibilityOff(); } if (m_Polygon) { ls->m_ContourActors->VisibilityOn(); //ApplyAllProperties(renderer, ls->m_ContourActors); //get contour color property if (dynamic_cast(this->GetDataNode()->GetPropertyList(renderer)->GetProperty("contourcolor")) != NULL) { tmpColor = dynamic_cast(this->GetDataNode()->GetPropertyList(renderer)->GetProperty("contourcolor"))->GetValue(); } else if (dynamic_cast(this->GetDataNode()->GetPropertyList(NULL)->GetProperty("contourcolor")) != NULL) { tmpColor = dynamic_cast(this->GetDataNode()->GetPropertyList(NULL)->GetProperty("contourcolor"))->GetValue(); } contourColor[0] = tmpColor[0]; contourColor[1] = tmpColor[1]; contourColor[2] = tmpColor[2]; contourColor[3] = 1.0f; ls->m_ContourActors->GetProperty()->SetColor(contourColor); ls->m_ContourActors->GetProperty()->SetOpacity(opacity); } else { ls->m_ContourActors->VisibilityOff(); } // create new vtk render objects (e.g. a circle for a point) this->CreateVTKRenderObjects(renderer); } void mitk::PointSetVtkMapper2D::ApplyAllProperties(mitk::BaseRenderer* renderer, vtkActor* actor) { Superclass::ApplyColorAndOpacityProperties(renderer, actor); } void mitk::PointSetVtkMapper2D::SetDefaultProperties(mitk::DataNode* node, mitk::BaseRenderer* renderer, bool overwrite) { node->AddProperty( "line width", mitk::IntProperty::New(2), renderer, overwrite ); // width of the line from one point to another node->AddProperty( "point line width", mitk::IntProperty::New(1), renderer, overwrite ); //width of the cross marking a point node->AddProperty( "point 2D size", mitk::IntProperty::New(2), renderer, overwrite ); // length of the cross marking a point // length of an edge of the box marking a point node->AddProperty( "show contour", mitk::BoolProperty::New(false), renderer, overwrite ); // contour of the line between points node->AddProperty( "close contour", mitk::BoolProperty::New(false), renderer, overwrite ); node->AddProperty( "show points", mitk::BoolProperty::New(true), renderer, overwrite ); //show or hide points node->AddProperty( "show distances", mitk::BoolProperty::New(false), renderer, overwrite ); //show or hide distance measure (not always available) node->AddProperty( "distance decimal digits", mitk::IntProperty::New(2), renderer, overwrite ); //set the number of decimal digits to be shown node->AddProperty( "show angles", mitk::BoolProperty::New(false), renderer, overwrite ); //show or hide angle measurement (not always available) node->AddProperty( "show distant lines", mitk::BoolProperty::New(false), renderer, overwrite ); //show the line between to points from a distant view (equals "always on top" option) node->AddProperty( "layer", mitk::IntProperty::New(1), renderer, overwrite ); // default to draw pointset above images (they have a default layer of 0) mitk::EnumerationProperty::Pointer glyphType = mitk::EnumerationProperty::New(); glyphType->AddEnum("None", 0); glyphType->AddEnum("Vertex", 1); glyphType->AddEnum("Dash", 2); glyphType->AddEnum("Cross", 3); glyphType->AddEnum("ThickCross", 4); glyphType->AddEnum("Triangle", 5); glyphType->AddEnum("Square", 6); glyphType->AddEnum("Circle", 7); glyphType->AddEnum("Diamond", 8); glyphType->AddEnum("Arrow", 9); glyphType->AddEnum("ThickArrow", 10); glyphType->AddEnum("HookedArrow", 11); glyphType->SetValue("Cross"); node->AddProperty( "glyph type", glyphType, renderer, overwrite); node->AddProperty("fill glyphs", mitk::BoolProperty::New(false), renderer, overwrite); // fill or do not fill the glyph shape Superclass::SetDefaultProperties(node, renderer, overwrite); } diff --git a/Core/Code/Rendering/mitkPointSetVtkMapper2D.h b/Core/Code/Rendering/mitkPointSetVtkMapper2D.h index 13d8ab306f..489dc004ca 100644 --- a/Core/Code/Rendering/mitkPointSetVtkMapper2D.h +++ b/Core/Code/Rendering/mitkPointSetVtkMapper2D.h @@ -1,242 +1,250 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKPointSetVtkMAPPER2D_H_HEADER_INCLUDED_C1902626 #define MITKPointSetVtkMAPPER2D_H_HEADER_INCLUDED_C1902626 #include #include "mitkVtkMapper.h" #include "mitkBaseRenderer.h" #include #include #include #include #include class vtkActor; class vtkPropAssembly; class vtkAppendPolyData; class vtkPolyData; class vtkTubeFilter; class vtkPolyDataMapper; class vtkGlyphSource2D; class vtkSphereSource; class vtkGlyph3D; class vtkFloatArray; namespace mitk { class PointSet; //TODO -- change commentar! /** * @brief Vtk-based mapper for PointSet * * Due to the need of different colors for selected * and unselected points and the facts, that we also have a contour and * labels for the points, the vtk structure is build up the following way: * * We have two AppendPolyData, one selected, and one unselected and one * for a contour between the points. Each one is connected to an own * PolyDaraMapper and an Actor. The different color for the unselected and * selected state and for the contour is read from properties. * * "unselectedcolor", "selectedcolor" and "contourcolor" are the strings, * that are looked for. Pointlabels are added besides the selected or the * deselected points. * * Then the three Actors are combined inside a vtkPropAssembly and this * object is returned in GetProp() and so hooked up into the rendering * pipeline. * Properties that can be set for point sets and influence the PointSetVTKMapper3D are: * * - \b "color": (ColorProperty*) Color of the point set * - \b "Opacity": (FloatProperty) Opacity of the point set * - \b "show contour": (BoolProperty) If the contour of the points are visible * - \b "contourSizeProp":(FloatProperty) Contour size of the points The default properties are: * - \b "line width": (IntProperty::New(2), renderer, overwrite ) * - \b "pointsize": (FloatProperty::New(1.0), renderer, overwrite) * - \b "selectedcolor": (ColorProperty::New(1.0f, 0.0f, 0.0f), renderer, overwrite) //red * - \b "color": (ColorProperty::New(1.0f, 1.0f, 0.0f), renderer, overwrite) //yellow * - \b "show contour": (BoolProperty::New(false), renderer, overwrite ) * - \b "contourcolor": (ColorProperty::New(1.0f, 0.0f, 0.0f), renderer, overwrite) * - \b "contoursize": (FloatProperty::New(0.5), renderer, overwrite ) * - \b "close contour": (BoolProperty::New(false), renderer, overwrite ) * - \b "show points": (BoolProperty::New(true), renderer, overwrite ) * - \b "updateDataOnRender": (BoolProperty::New(true), renderer, overwrite ) *Other properties looked for are: * * - \b "show contour": if set to on, lines between the points are shown * - \b "close contour": if set to on, the open strip is closed (first point * connected with last point) * - \b "pointsize": size of the points mapped * - \b "label": text of the Points to show besides points * - \b "contoursize": size of the contour drawn between the points * (if not set, the pointsize is taken) * * @ingroup Mapper */ class MITK_CORE_EXPORT PointSetVtkMapper2D : public VtkMapper { public: mitkClassMacro(PointSetVtkMapper2D, VtkMapper); itkNewMacro(Self); //TODO: change to GetInputConnection() virtual const mitk::PointSet* GetInput(); //overwritten from VtkMapper3D to be able to return a //m_PropAssemblies which is much faster than a vtkAssembly virtual vtkProp* GetVtkProp(mitk::BaseRenderer* renderer); static void SetDefaultProperties(mitk::DataNode* node, mitk::BaseRenderer* renderer = NULL, bool overwrite = false); //void ReleaseGraphicsResources(vtkWindow *renWin); //enum Glyph2DType{Vertex, Dash, Cross, ThickCross, Triangle, Square, Circle, Diamond, Arrow, ThickArrow, HookedArrow}; /** \brief Internal class holding the mapper, actor, etc. for each of the 3 2D render windows */ class LocalStorage : public mitk::Mapper::BaseLocalStorage { public: // use std::vector because of the three 2D render windows vtkSmartPointer m_VtkUnselectedPolyDataMappers; vtkSmartPointer m_VtkSelectedPolyDataMappers; vtkSmartPointer m_VtkContourPolyDataMappers; vtkSmartPointer m_VtkUnselectedPointListPolyData; vtkSmartPointer m_VtkSelectedPointListPolyData; vtkSmartPointer m_VtkContourPolyData; vtkSmartPointer m_UnselectedActors; vtkSmartPointer m_SelectedActors; vtkSmartPointer m_ContourActors; vtkSmartPointer m_PropAssemblies; vtkSmartPointer m_UnselectedPoints; vtkSmartPointer m_SelectedPoints; vtkSmartPointer m_ContourPoints; vtkSmartPointer m_UnselectedGlyph3D; vtkSmartPointer m_SelectedGlyph3D; - // Setup scales + vtkSmartPointer m_DistancesBetweenPoints; vtkSmartPointer m_UnselectedScales; vtkSmartPointer m_SelectedScales; vtkSmartPointer m_UnselectedGlyphSource2D; vtkSmartPointer m_SelectedGlyphSource2D; - //help for contour between points - // vtkSmartPointer m_vtkTextList; + + vtkSmartPointer m_VtkTextPolyData; + vtkSmartPointer m_VtkTextPolyDataMapper; + vtkSmartPointer m_VtkTextActor; LocalStorage() { + m_VtkTextPolyData = vtkSmartPointer::New(); + m_VtkTextPolyDataMapper = vtkSmartPointer::New(); + m_VtkTextActor = vtkSmartPointer::New(); + // mappers m_VtkUnselectedPolyDataMappers = vtkSmartPointer::New(); m_VtkSelectedPolyDataMappers = vtkSmartPointer::New(); m_VtkContourPolyDataMappers = vtkSmartPointer::New(); - // Setup scales + // scales m_UnselectedScales = vtkSmartPointer::New(); m_SelectedScales = vtkSmartPointer::New(); + // distances + m_DistancesBetweenPoints = vtkSmartPointer::New(); // polydata m_VtkUnselectedPointListPolyData = vtkSmartPointer::New(); m_VtkSelectedPointListPolyData = vtkSmartPointer ::New(); m_VtkContourPolyData = vtkSmartPointer::New(); // actors m_UnselectedActors = vtkSmartPointer ::New(); m_SelectedActors = vtkSmartPointer ::New(); m_ContourActors = vtkSmartPointer ::New(); // propassembly m_PropAssemblies = vtkSmartPointer ::New(); // points m_UnselectedPoints = vtkSmartPointer::New(); m_SelectedPoints = vtkSmartPointer::New(); m_ContourPoints = vtkSmartPointer::New(); // glyphs m_UnselectedGlyph3D = vtkSmartPointer::New(); m_SelectedGlyph3D = vtkSmartPointer::New(); // glyph source (provides the different shapes) m_UnselectedGlyphSource2D = vtkSmartPointer::New(); m_SelectedGlyphSource2D = vtkSmartPointer::New(); } ~LocalStorage() {}; }; /** \brief The LocalStorageHandler holds all (three) LocalStorages for the three 2D render windows. */ mitk::Mapper::LocalStorageHandler m_LSH; protected: PointSetVtkMapper2D(); virtual ~PointSetVtkMapper2D(); virtual void GenerateDataForRenderer(mitk::BaseRenderer* renderer); virtual void ResetMapper( BaseRenderer* renderer ); virtual void ApplyAllProperties(mitk::BaseRenderer* renderer, vtkActor* actor); virtual void CreateVTKRenderObjects(mitk::BaseRenderer* renderer); bool m_Polygon; bool m_PolygonClosed; bool m_ShowPoints; bool m_ShowDistances; int m_DistancesDecimalDigits; bool m_ShowAngles; bool m_ShowDistantLines; int m_LineWidth; int m_PointLineWidth; int m_Point2DSize; //Glyph2DType m_GlyphType; //mitk::EnumerationProperty::IdType int m_IdGlyph; bool m_FillGlyphs; }; } // namespace mitk #endif /* MITKPointSetVtkMAPPER2D_H_HEADER_INCLUDED_C1902626 */ diff --git a/Modules/MitkExt/Rendering/mitkLineMapper2D.cpp b/Modules/MitkExt/Rendering/mitkLineMapper2D.cpp index 19560e23ca..c310ddb53e 100644 --- a/Modules/MitkExt/Rendering/mitkLineMapper2D.cpp +++ b/Modules/MitkExt/Rendering/mitkLineMapper2D.cpp @@ -1,140 +1,140 @@ -/*=================================================================== - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. -All rights reserved. - -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. - -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ - - -#include "mitkLineMapper2D.h" -#include "mitkPointSet.h" -#include "mitkBaseRenderer.h" -#include "mitkPlaneGeometry.h" -#include "mitkColorProperty.h" -#include "mitkProperties.h" -#include -#include "mitkPointSet.h" -#include "mitkGL.h" - -mitk::LineMapper2D::LineMapper2D() -: mitk::PointSetGLMapper2D() -{ - -} - -mitk::LineMapper2D::~LineMapper2D() -{ -} - -const mitk::PointSet *mitk::LineMapper2D::GetInput(void) -{ - return static_cast ( GetDataNode()->GetData() ); -} - -void mitk::LineMapper2D::Paint(mitk::BaseRenderer * renderer) -{ - - bool visible = true; - GetDataNode()->GetVisibility(visible, renderer, "visible"); - if(!visible) return; - - bool updateNeccesary = true;//!!!! @TODO !??!! - - if (updateNeccesary) - { - mitk::PointSet::Pointer input = const_cast(this->GetInput()); - mitk::DisplayGeometry::Pointer displayGeometry = renderer->GetDisplayGeometry(); - assert(displayGeometry.IsNotNull()); - - //apply color and opacity read from the PropertyList - ApplyColorAndOpacityProperties(renderer); - - vtkLinearTransform* transform = GetDataNode()->GetVtkTransform(); - - //List of the Points - PointSet::DataType::PointsContainerConstIterator it, end; - it = input->GetPointSet()->GetPoints()->Begin(); - end = input->GetPointSet()->GetPoints()->End();//the last before end, because lines from n to n+1 - if (end!=it) // otherwise PointSet is empty - end--; - - //bool list for the selection of the points - PointSet::DataType::PointDataContainerIterator selIt, selItNext; - selIt=input->GetPointSet()->GetPointData()->Begin(); - - int j=0; - while(it!=end) - { - mitk::Point3D p, q, projected_p, projected_q; - float vtkp[3]; - itk2vtk(it->Value(), vtkp); - transform->TransformPoint(vtkp, vtkp); - vtk2itk(vtkp,p); - - //next point n+1 - it++; - itk2vtk(it->Value(), vtkp); - transform->TransformPoint(vtkp, vtkp); - vtk2itk(vtkp,q); - it--; - - displayGeometry->Project(p, projected_p); - displayGeometry->Project(q, projected_q); - - Vector3D diffp=p-projected_p, diffq=q-projected_q; - if((diffp.GetSquaredNorm()<4.0) && - (diffq.GetSquaredNorm()<4.0)) - { - Point2D p2d, q2d, tmp; - - displayGeometry->Map(projected_p, p2d); - displayGeometry->WorldToDisplay(p2d, p2d); - displayGeometry->Map(projected_q, q2d); - displayGeometry->WorldToDisplay(q2d, q2d); - - //outlined, cause iterators behave strange and multiple points can't be selected anyway by now! - //selItNext = selIt++;//Iterator to the next Element, cause only when the two points ar selected, then the Line is Selected - //if (selIt->Value() && selItNext->Value())//selected - //{ - // float colorSel[]={1.0,0.0,0.6}; //for selected! - - // //current color for changing to a diferent color if selected - // float currCol[4]; - // glGetFloatv(GL_CURRENT_COLOR,currCol); - - // glColor3f(colorSel[0],colorSel[1],colorSel[2]);//red - - - // glBegin (GL_LINES); - // glVertex2f(p2d[0], p2d[1]); - // glVertex2f(q2d[0], q2d[1]); - // glEnd (); - - // glColor3f(currCol[0],currCol[1],currCol[2]);//the color before changing to select! - - //} - //else - //{ - glBegin (GL_LINES); - glVertex2f(p2d[0], p2d[1]); - glVertex2f(q2d[0], q2d[1]); - glEnd (); - //} - } - ++it; - ++selIt; - j++; - } - //drawing the points - PointSetGLMapper2D::Paint(renderer); - } -} +///*=================================================================== +// +//The Medical Imaging Interaction Toolkit (MITK) +// +//Copyright (c) German Cancer Research Center, +//Division of Medical and Biological Informatics. +//All rights reserved. +// +//This software is distributed WITHOUT ANY WARRANTY; without +//even the implied warranty of MERCHANTABILITY or FITNESS FOR +//A PARTICULAR PURPOSE. +// +//See LICENSE.txt or http://www.mitk.org for details. +// +//===================================================================*/ +// +// +//#include "mitkLineMapper2D.h" +//#include "mitkPointSet.h" +//#include "mitkBaseRenderer.h" +//#include "mitkPlaneGeometry.h" +//#include "mitkColorProperty.h" +//#include "mitkProperties.h" +//#include +//#include "mitkPointSet.h" +//#include "mitkGL.h" +// +//mitk::LineMapper2D::LineMapper2D() +//: mitk::PointSetGLMapper2D() +//{ +// +//} +// +//mitk::LineMapper2D::~LineMapper2D() +//{ +//} +// +//const mitk::PointSet *mitk::LineMapper2D::GetInput(void) +//{ +// return static_cast ( GetDataNode()->GetData() ); +//} +// +//void mitk::LineMapper2D::Paint(mitk::BaseRenderer * renderer) +//{ +// +// bool visible = true; +// GetDataNode()->GetVisibility(visible, renderer, "visible"); +// if(!visible) return; +// +// bool updateNeccesary = true;//!!!! @TODO !??!! +// +// if (updateNeccesary) +// { +// mitk::PointSet::Pointer input = const_cast(this->GetInput()); +// mitk::DisplayGeometry::Pointer displayGeometry = renderer->GetDisplayGeometry(); +// assert(displayGeometry.IsNotNull()); +// +// //apply color and opacity read from the PropertyList +// ApplyColorAndOpacityProperties(renderer); +// +// vtkLinearTransform* transform = GetDataNode()->GetVtkTransform(); +// +// //List of the Points +// PointSet::DataType::PointsContainerConstIterator it, end; +// it = input->GetPointSet()->GetPoints()->Begin(); +// end = input->GetPointSet()->GetPoints()->End();//the last before end, because lines from n to n+1 +// if (end!=it) // otherwise PointSet is empty +// end--; +// +// //bool list for the selection of the points +// PointSet::DataType::PointDataContainerIterator selIt, selItNext; +// selIt=input->GetPointSet()->GetPointData()->Begin(); +// +// int j=0; +// while(it!=end) +// { +// mitk::Point3D p, q, projected_p, projected_q; +// float vtkp[3]; +// itk2vtk(it->Value(), vtkp); +// transform->TransformPoint(vtkp, vtkp); +// vtk2itk(vtkp,p); +// +// //next point n+1 +// it++; +// itk2vtk(it->Value(), vtkp); +// transform->TransformPoint(vtkp, vtkp); +// vtk2itk(vtkp,q); +// it--; +// +// displayGeometry->Project(p, projected_p); +// displayGeometry->Project(q, projected_q); +// +// Vector3D diffp=p-projected_p, diffq=q-projected_q; +// if((diffp.GetSquaredNorm()<4.0) && +// (diffq.GetSquaredNorm()<4.0)) +// { +// Point2D p2d, q2d, tmp; +// +// displayGeometry->Map(projected_p, p2d); +// displayGeometry->WorldToDisplay(p2d, p2d); +// displayGeometry->Map(projected_q, q2d); +// displayGeometry->WorldToDisplay(q2d, q2d); +// +// //outlined, cause iterators behave strange and multiple points can't be selected anyway by now! +// //selItNext = selIt++;//Iterator to the next Element, cause only when the two points ar selected, then the Line is Selected +// //if (selIt->Value() && selItNext->Value())//selected +// //{ +// // float colorSel[]={1.0,0.0,0.6}; //for selected! +// +// // //current color for changing to a diferent color if selected +// // float currCol[4]; +// // glGetFloatv(GL_CURRENT_COLOR,currCol); +// +// // glColor3f(colorSel[0],colorSel[1],colorSel[2]);//red +// +// +// // glBegin (GL_LINES); +// // glVertex2f(p2d[0], p2d[1]); +// // glVertex2f(q2d[0], q2d[1]); +// // glEnd (); +// +// // glColor3f(currCol[0],currCol[1],currCol[2]);//the color before changing to select! +// +// //} +// //else +// //{ +// glBegin (GL_LINES); +// glVertex2f(p2d[0], p2d[1]); +// glVertex2f(q2d[0], q2d[1]); +// glEnd (); +// //} +// } +// ++it; +// ++selIt; +// j++; +// } +// //drawing the points +// PointSetGLMapper2D::Paint(renderer); +// } +//} diff --git a/Modules/MitkExt/Rendering/mitkLineMapper2D.h b/Modules/MitkExt/Rendering/mitkLineMapper2D.h index 522422e51c..f7a29db08a 100644 --- a/Modules/MitkExt/Rendering/mitkLineMapper2D.h +++ b/Modules/MitkExt/Rendering/mitkLineMapper2D.h @@ -1,56 +1,56 @@ -/*=================================================================== - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. -All rights reserved. - -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. - -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ - - -#ifndef MITKLINEMAPPER2D_H_HEADER_INCLUDED -#define MITKLINEMAPPER2D_H_HEADER_INCLUDED - -#include "mitkCommon.h" -#include "MitkExtExports.h" -#include "mitkPointSetGLMapper2D.h" - -namespace mitk { - -class BaseRenderer; -class PointSet; - -//##Documentation -//## @brief OpenGL-based mapper to display Lines -//## -//## uses the information from the PointSet to build up the lines. -//## Only lines in 2D in one Slice are drawn, not between slices! -//## @ingroup Mapper -class MitkExt_EXPORT LineMapper2D : public PointSetGLMapper2D -{ -public: - mitkClassMacro(LineMapper2D, PointSetGLMapper2D); - itkNewMacro(Self); - - //##Documentation - //## @brief Get the PointDataList to map - const PointSet * GetInput(void); - - virtual void Paint(mitk::BaseRenderer * renderer); - -protected: - LineMapper2D(); - - virtual ~LineMapper2D(); -}; - -} // namespace mitk - -#endif /* MITKLINEMAPPER2D_H_HEADER_INCLUDED */ +///*=================================================================== +// +//The Medical Imaging Interaction Toolkit (MITK) +// +//Copyright (c) German Cancer Research Center, +//Division of Medical and Biological Informatics. +//All rights reserved. +// +//This software is distributed WITHOUT ANY WARRANTY; without +//even the implied warranty of MERCHANTABILITY or FITNESS FOR +//A PARTICULAR PURPOSE. +// +//See LICENSE.txt or http://www.mitk.org for details. +// +//===================================================================*/ +// +// +//#ifndef MITKLINEMAPPER2D_H_HEADER_INCLUDED +//#define MITKLINEMAPPER2D_H_HEADER_INCLUDED +// +//#include "mitkCommon.h" +//#include "MitkExtExports.h" +//#include "mitkPointSetGLMapper2D.h" +// +//namespace mitk { +// +//class BaseRenderer; +//class PointSet; +// +////##Documentation +////## @brief OpenGL-based mapper to display Lines +////## +////## uses the information from the PointSet to build up the lines. +////## Only lines in 2D in one Slice are drawn, not between slices! +////## @ingroup Mapper +//class MitkExt_EXPORT LineMapper2D : public PointSetGLMapper2D +//{ +//public: +// mitkClassMacro(LineMapper2D, PointSetGLMapper2D); +// itkNewMacro(Self); +// +// //##Documentation +// //## @brief Get the PointDataList to map +// const PointSet * GetInput(void); +// +// virtual void Paint(mitk::BaseRenderer * renderer); +// +//protected: +// LineMapper2D(); +// +// virtual ~LineMapper2D(); +//}; +// +//} // namespace mitk +// +//#endif /* MITKLINEMAPPER2D_H_HEADER_INCLUDED */ diff --git a/Modules/MitkExt/Rendering/mitkSplineMapper2D.cpp b/Modules/MitkExt/Rendering/mitkSplineMapper2D.cpp index f81f3c4a35..8fd473c4a6 100755 --- a/Modules/MitkExt/Rendering/mitkSplineMapper2D.cpp +++ b/Modules/MitkExt/Rendering/mitkSplineMapper2D.cpp @@ -1,193 +1,193 @@ -/*=================================================================== - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. -All rights reserved. - -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. - -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ - - -#include "mitkSplineMapper2D.h" -#include "mitkSplineVtkMapper3D.h" -#include -#include -#include -#include -#include -#include -#include -#include - -void mitk::SplineMapper2D::Paint ( mitk::BaseRenderer * renderer ) -{ - Superclass::Paint ( renderer ); - - bool visible = true; - GetDataNode()->GetVisibility(visible, renderer, "visible"); - - if ( !visible ) - return; - - // - // get the poly data of the splines in 3D - // - mitk::SplineVtkMapper3D::Pointer mapper3D = dynamic_cast ( this->GetDataNode()->GetMapper ( 2 ) ); - if ( mapper3D.IsNull() ) - { - itkWarningMacro ( "Mapper used for 3D mapping is not a mitk::SplineVtkMapper3D!" ); - return; - } - // - // update the 3D spline, if the accoring mapper has not been updated yet - // - if ( mapper3D->GetLastUpdateTime() < GetDataNode()->GetData()->GetMTime() ) - mapper3D->UpdateSpline(); - vtkPolyData* spline3D = NULL; - if ( mapper3D->SplinesAreAvailable() ) - spline3D = mapper3D->GetSplinesPolyData(); - else - return; - if ( spline3D == NULL ) - { - itkWarningMacro ( "3D spline is not available!" ); - return; - } - // - // get the transform associated with the data tree node - // - vtkLinearTransform* transform = this->GetDataNode()->GetVtkTransform(); - if ( transform == NULL ) - { - itkWarningMacro("transfrom is NULL"); - } - - // - // get the plane geometry of the current renderer - // - mitk::Geometry2D::ConstPointer worldGeometry = renderer->GetCurrentWorldGeometry2D(); - if ( worldGeometry.IsNull() ) - { - itkWarningMacro("worldGeometry is NULL!"); - return; - } - PlaneGeometry::ConstPointer worldPlaneGeometry = dynamic_cast ( worldGeometry.GetPointer() ); - if ( worldPlaneGeometry.IsNull() ) - { - itkWarningMacro("worldPlaneGeometry is NULL!"); - return; - } - - // - // determine color of the spline - // - float color[3]; - this->GetDataNode()->GetColor ( color, renderer ); - - // - // iterate over the points - // - vtkPoints *vpoints = spline3D->GetPoints(); - vtkCellArray *vlines = spline3D->GetLines(); - if (vpoints == NULL) - { - itkWarningMacro("points are NULL!"); - return; - } - if (vlines == NULL) - { - itkWarningMacro("lines are NULL!"); - return; - } - - mitk::Point3D currentPoint3D; - mitk::Point2D currentPoint2D; - vtkFloatingPointType currentPoint3DVtk[3]; - - vlines->InitTraversal(); - int numberOfLines = vlines->GetNumberOfCells(); - vtkFloatingPointType currentPointDistance; - for ( int i = 0;i < numberOfLines; ++i ) - { - bool previousPointOnPlane = false; - bool currentPointOnPlane = false; - vtkIdType* cell ( NULL ); - vtkIdType cellSize ( 0 ); - vlines->GetNextCell ( cellSize, cell ); - for ( int j = 0 ; j < cellSize; ++j ) - { - vpoints->GetPoint ( cell[j], currentPoint3DVtk ); - - // take transformation via vtktransform into account - transform->TransformPoint ( currentPoint3DVtk, currentPoint3DVtk ); - vtk2itk ( currentPoint3DVtk, currentPoint3D ); - - // check if the point has a distance to the plane - // which is smaller than m_MaxProjectionDistance - currentPointDistance = worldPlaneGeometry->DistanceFromPlane ( currentPoint3D ); - - if ( currentPointDistance < m_MaxProjectionDistance ) - { - currentPointOnPlane = true; - //convert 3D point (in mm) to 2D point on slice (also in mm) - worldGeometry->Map ( currentPoint3D, currentPoint2D ); - //convert point (until now mm and in worldcoordinates) to display coordinates (units ) - renderer->GetDisplayGeometry()->WorldToDisplay ( currentPoint2D, currentPoint2D ); - } - else - currentPointOnPlane = false; - - // - // check if we have to begin or end a GL_LINE - // - if ( ( previousPointOnPlane == false ) && ( currentPointOnPlane == true ) ) - { - glLineWidth ( m_LineWidth ); - glColor3f ( color[0], color[1], color[2] ); - glBegin ( GL_LINE_STRIP ); - } - else if ( ( previousPointOnPlane == true ) && ( currentPointOnPlane == false ) ) - { - glEnd (); - glLineWidth ( 1.0 ); - } - // the current ponit is on the plane, add it as point to the - // line segment - if ( currentPointOnPlane == true ) - { - glVertex2f ( currentPoint2D[0], currentPoint2D[1] ); - } - previousPointOnPlane = currentPointOnPlane; - } - // the last point of the spline segment is on the plane, thus we have to - // close the GL_LINE - if ( previousPointOnPlane == true ) - { - glEnd (); - glLineWidth ( 1.0 ); - } - previousPointOnPlane = false; - } -} - -void mitk::SplineMapper2D::ApplyProperties ( mitk::BaseRenderer* renderer ) -{ - ApplyColorAndOpacityProperties ( renderer ); -} - -mitk::SplineMapper2D::SplineMapper2D() -{ - m_MaxProjectionDistance = 1; - m_ShowDistantLines = false ; - m_LineWidth = 1; -} - -mitk::SplineMapper2D::~SplineMapper2D() -{} +///*=================================================================== +// +//The Medical Imaging Interaction Toolkit (MITK) +// +//Copyright (c) German Cancer Research Center, +//Division of Medical and Biological Informatics. +//All rights reserved. +// +//This software is distributed WITHOUT ANY WARRANTY; without +//even the implied warranty of MERCHANTABILITY or FITNESS FOR +//A PARTICULAR PURPOSE. +// +//See LICENSE.txt or http://www.mitk.org for details. +// +//===================================================================*/ +// +// +//#include "mitkSplineMapper2D.h" +//#include "mitkSplineVtkMapper3D.h" +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +// +//void mitk::SplineMapper2D::Paint ( mitk::BaseRenderer * renderer ) +//{ +// Superclass::Paint ( renderer ); +// +// bool visible = true; +// GetDataNode()->GetVisibility(visible, renderer, "visible"); +// +// if ( !visible ) +// return; +// +// // +// // get the poly data of the splines in 3D +// // +// mitk::SplineVtkMapper3D::Pointer mapper3D = dynamic_cast ( this->GetDataNode()->GetMapper ( 2 ) ); +// if ( mapper3D.IsNull() ) +// { +// itkWarningMacro ( "Mapper used for 3D mapping is not a mitk::SplineVtkMapper3D!" ); +// return; +// } +// // +// // update the 3D spline, if the accoring mapper has not been updated yet +// // +// if ( mapper3D->GetLastUpdateTime() < GetDataNode()->GetData()->GetMTime() ) +// mapper3D->UpdateSpline(); +// vtkPolyData* spline3D = NULL; +// if ( mapper3D->SplinesAreAvailable() ) +// spline3D = mapper3D->GetSplinesPolyData(); +// else +// return; +// if ( spline3D == NULL ) +// { +// itkWarningMacro ( "3D spline is not available!" ); +// return; +// } +// // +// // get the transform associated with the data tree node +// // +// vtkLinearTransform* transform = this->GetDataNode()->GetVtkTransform(); +// if ( transform == NULL ) +// { +// itkWarningMacro("transfrom is NULL"); +// } +// +// // +// // get the plane geometry of the current renderer +// // +// mitk::Geometry2D::ConstPointer worldGeometry = renderer->GetCurrentWorldGeometry2D(); +// if ( worldGeometry.IsNull() ) +// { +// itkWarningMacro("worldGeometry is NULL!"); +// return; +// } +// PlaneGeometry::ConstPointer worldPlaneGeometry = dynamic_cast ( worldGeometry.GetPointer() ); +// if ( worldPlaneGeometry.IsNull() ) +// { +// itkWarningMacro("worldPlaneGeometry is NULL!"); +// return; +// } +// +// // +// // determine color of the spline +// // +// float color[3]; +// this->GetDataNode()->GetColor ( color, renderer ); +// +// // +// // iterate over the points +// // +// vtkPoints *vpoints = spline3D->GetPoints(); +// vtkCellArray *vlines = spline3D->GetLines(); +// if (vpoints == NULL) +// { +// itkWarningMacro("points are NULL!"); +// return; +// } +// if (vlines == NULL) +// { +// itkWarningMacro("lines are NULL!"); +// return; +// } +// +// mitk::Point3D currentPoint3D; +// mitk::Point2D currentPoint2D; +// vtkFloatingPointType currentPoint3DVtk[3]; +// +// vlines->InitTraversal(); +// int numberOfLines = vlines->GetNumberOfCells(); +// vtkFloatingPointType currentPointDistance; +// for ( int i = 0;i < numberOfLines; ++i ) +// { +// bool previousPointOnPlane = false; +// bool currentPointOnPlane = false; +// vtkIdType* cell ( NULL ); +// vtkIdType cellSize ( 0 ); +// vlines->GetNextCell ( cellSize, cell ); +// for ( int j = 0 ; j < cellSize; ++j ) +// { +// vpoints->GetPoint ( cell[j], currentPoint3DVtk ); +// +// // take transformation via vtktransform into account +// transform->TransformPoint ( currentPoint3DVtk, currentPoint3DVtk ); +// vtk2itk ( currentPoint3DVtk, currentPoint3D ); +// +// // check if the point has a distance to the plane +// // which is smaller than m_MaxProjectionDistance +// currentPointDistance = worldPlaneGeometry->DistanceFromPlane ( currentPoint3D ); +// +// if ( currentPointDistance < m_MaxProjectionDistance ) +// { +// currentPointOnPlane = true; +// //convert 3D point (in mm) to 2D point on slice (also in mm) +// worldGeometry->Map ( currentPoint3D, currentPoint2D ); +// //convert point (until now mm and in worldcoordinates) to display coordinates (units ) +// renderer->GetDisplayGeometry()->WorldToDisplay ( currentPoint2D, currentPoint2D ); +// } +// else +// currentPointOnPlane = false; +// +// // +// // check if we have to begin or end a GL_LINE +// // +// if ( ( previousPointOnPlane == false ) && ( currentPointOnPlane == true ) ) +// { +// glLineWidth ( m_LineWidth ); +// glColor3f ( color[0], color[1], color[2] ); +// glBegin ( GL_LINE_STRIP ); +// } +// else if ( ( previousPointOnPlane == true ) && ( currentPointOnPlane == false ) ) +// { +// glEnd (); +// glLineWidth ( 1.0 ); +// } +// // the current ponit is on the plane, add it as point to the +// // line segment +// if ( currentPointOnPlane == true ) +// { +// glVertex2f ( currentPoint2D[0], currentPoint2D[1] ); +// } +// previousPointOnPlane = currentPointOnPlane; +// } +// // the last point of the spline segment is on the plane, thus we have to +// // close the GL_LINE +// if ( previousPointOnPlane == true ) +// { +// glEnd (); +// glLineWidth ( 1.0 ); +// } +// previousPointOnPlane = false; +// } +//} +// +//void mitk::SplineMapper2D::ApplyProperties ( mitk::BaseRenderer* renderer ) +//{ +// ApplyColorAndOpacityProperties ( renderer ); +//} +// +//mitk::SplineMapper2D::SplineMapper2D() +//{ +// m_MaxProjectionDistance = 1; +// m_ShowDistantLines = false ; +// m_LineWidth = 1; +//} +// +//mitk::SplineMapper2D::~SplineMapper2D() +//{} diff --git a/Modules/MitkExt/Rendering/mitkSplineMapper2D.h b/Modules/MitkExt/Rendering/mitkSplineMapper2D.h index 30c6d704fa..e23db3ae5d 100755 --- a/Modules/MitkExt/Rendering/mitkSplineMapper2D.h +++ b/Modules/MitkExt/Rendering/mitkSplineMapper2D.h @@ -1,83 +1,83 @@ -/*=================================================================== - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. -All rights reserved. - -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. - -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ - - -#ifndef MITKSplineMapper2D_H_HEADER_INCLUDED -#define MITKSplineMapper2D_H_HEADER_INCLUDED - -#include "mitkCommon.h" -#include "MitkExtExports.h" -#include "mitkGLMapper.h" -#include "mitkPointSetGLMapper2D.h" -#include - -namespace mitk -{ - -class BaseRenderer; -class PointSet; - -//##Documentation -//## @brief OpenGL-based mapper to display a spline based on a mitk::PointSet in a 2D window. -//## -/** This mapper can actually more than just draw a number of points of a -* mitk::PointSet. If you set the right properties of the mitk::DataNode, -* which contains the point set, then this mapper will also draw lines -* connecting the points, and calculate and display distances and angles -* between adjacent points. Here is a complete list of boolean properties, -* which might be of interest: -* -* - \b "show contour": Draw not only the points but also the connections between -* them (default false) -* - \b "line width": IntProperty which gives the width of the contour lines -* - \b "show points": Wheter or not to draw the actual points (default true) -* - \b "show distances": Wheter or not to calculate and print the distance -* between adjacent points (default false) -* - \b "show angles": Wheter or not to calculate and print the angle between -* adjacent points (default false) -* - \b "show distant lines": When true, the mapper will also draw contour -* lines that are far away form the current slice (default true) -* - \b "label": StringProperty with a label for this point set -*/ -//## @ingroup Mapper -class MitkExt_EXPORT SplineMapper2D : public PointSetGLMapper2D -{ -public: - mitkClassMacro ( SplineMapper2D, PointSetGLMapper2D ); - - itkNewMacro ( Self ); - - virtual void Paint ( mitk::BaseRenderer * renderer ); - - virtual void ApplyProperties ( mitk::BaseRenderer* renderer ); - - itkSetMacro ( MaxProjectionDistance, vtkFloatingPointType ); - - itkGetMacro ( MaxProjectionDistance, vtkFloatingPointType ); - -protected: - SplineMapper2D(); - - virtual ~SplineMapper2D(); - - vtkFloatingPointType m_MaxProjectionDistance; -}; - -} // namespace mitk - - - -#endif /* MITKSplineMapper2D_H_HEADER_INCLUDED */ +///*=================================================================== +// +//The Medical Imaging Interaction Toolkit (MITK) +// +//Copyright (c) German Cancer Research Center, +//Division of Medical and Biological Informatics. +//All rights reserved. +// +//This software is distributed WITHOUT ANY WARRANTY; without +//even the implied warranty of MERCHANTABILITY or FITNESS FOR +//A PARTICULAR PURPOSE. +// +//See LICENSE.txt or http://www.mitk.org for details. +// +//===================================================================*/ +// +// +//#ifndef MITKSplineMapper2D_H_HEADER_INCLUDED +//#define MITKSplineMapper2D_H_HEADER_INCLUDED +// +//#include "mitkCommon.h" +//#include "MitkExtExports.h" +//#include "mitkGLMapper.h" +//#include "mitkPointSetGLMapper2D.h" +//#include +// +//namespace mitk +//{ +// +//class BaseRenderer; +//class PointSet; +// +////##Documentation +////## @brief OpenGL-based mapper to display a spline based on a mitk::PointSet in a 2D window. +////## +///** This mapper can actually more than just draw a number of points of a +//* mitk::PointSet. If you set the right properties of the mitk::DataNode, +//* which contains the point set, then this mapper will also draw lines +//* connecting the points, and calculate and display distances and angles +//* between adjacent points. Here is a complete list of boolean properties, +//* which might be of interest: +//* +//* - \b "show contour": Draw not only the points but also the connections between +//* them (default false) +//* - \b "line width": IntProperty which gives the width of the contour lines +//* - \b "show points": Wheter or not to draw the actual points (default true) +//* - \b "show distances": Wheter or not to calculate and print the distance +//* between adjacent points (default false) +//* - \b "show angles": Wheter or not to calculate and print the angle between +//* adjacent points (default false) +//* - \b "show distant lines": When true, the mapper will also draw contour +//* lines that are far away form the current slice (default true) +//* - \b "label": StringProperty with a label for this point set +//*/ +////## @ingroup Mapper +//class MitkExt_EXPORT SplineMapper2D : public PointSetGLMapper2D +//{ +//public: +// mitkClassMacro ( SplineMapper2D, PointSetGLMapper2D ); +// +// itkNewMacro ( Self ); +// +// virtual void Paint ( mitk::BaseRenderer * renderer ); +// +// virtual void ApplyProperties ( mitk::BaseRenderer* renderer ); +// +// itkSetMacro ( MaxProjectionDistance, vtkFloatingPointType ); +// +// itkGetMacro ( MaxProjectionDistance, vtkFloatingPointType ); +// +//protected: +// SplineMapper2D(); +// +// virtual ~SplineMapper2D(); +// +// vtkFloatingPointType m_MaxProjectionDistance; +//}; +// +//} // namespace mitk +// +// +// +//#endif /* MITKSplineMapper2D_H_HEADER_INCLUDED */ diff --git a/Modules/MitkExt/Testing/mitkDataNodeExtTest.cpp b/Modules/MitkExt/Testing/mitkDataNodeExtTest.cpp index 5b9dfd95b8..40d5725499 100644 --- a/Modules/MitkExt/Testing/mitkDataNodeExtTest.cpp +++ b/Modules/MitkExt/Testing/mitkDataNodeExtTest.cpp @@ -1,213 +1,213 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkDataNode.h" #include #include "mitkVtkPropRenderer.h" #include "mitkTestingMacros.h" #include "mitkGlobalInteraction.h" #include //Basedata Test #include #include #include #include #include //Mapper Test #include #include #include #include #include #include #include #include #include #include #include //Interactors #include #include #include #include #include //Propertylist Test #include #include #include #include #include #include #include #include #include #include #include /** * Extended test for mitk::DataNode. A number of tests from the core test * mitkDataNodeTest are assumed to pass! */ class mitkDataNodeExtTestClass { public: static void TestDataSetting(mitk::DataNode::Pointer dataNode) { mitk::BaseData::Pointer baseData; //NULL pointer Test dataNode->SetData(baseData); MITK_TEST_CONDITION( baseData == dataNode->GetData(), "Testing if a NULL pointer was set correctly" ) baseData = mitk::ItkBaseDataAdapter::New(); dataNode->SetData(baseData); MITK_TEST_CONDITION( baseData == dataNode->GetData(), "Testing if a ItkBaseDataAdapter object was set correctly" ) baseData = mitk::Mesh::New(); dataNode->SetData(baseData); MITK_TEST_CONDITION( baseData == dataNode->GetData(), "Testing if a Mesh object was set correctly" ) baseData = mitk::SeedsImage::New(); dataNode->SetData(baseData); MITK_TEST_CONDITION( baseData == dataNode->GetData(), "Testing if a SeedsImage object was set correctly" ) baseData = mitk::BoundingObject::New(); dataNode->SetData(baseData); MITK_TEST_CONDITION( baseData == dataNode->GetData(), "Testing if a BoundingObject object was set correctly" ) baseData = mitk::UnstructuredGrid::New(); dataNode->SetData(baseData); MITK_TEST_CONDITION( baseData == dataNode->GetData(), "Testing if a UnstructuredGrid object was set correctly" ) } static void TestMapperSetting(mitk::DataNode::Pointer dataNode) { //tests the SetMapper() method //in dataNode is a mapper vector which can be accessed by index //in this test method we use only slot 0 (filled with null) and slot 1 //so we also test the destructor of the mapper classes mitk::Mapper::Pointer mapper; dataNode->SetMapper(0,mapper); MITK_TEST_CONDITION( mapper == dataNode->GetMapper(0), "Testing if a NULL pointer was set correctly" ) mapper = mitk::MeshMapper2D::New(); dataNode->SetMapper(1,mapper); MITK_TEST_CONDITION( mapper == dataNode->GetMapper(1), "Testing if a MeshMapper2D was set correctly" ) MITK_TEST_CONDITION( dataNode == mapper->GetDataNode(), "Testing if the mapper returns the right DataNode" ) mapper = mitk::UnstructuredGridMapper2D::New(); dataNode->SetMapper(1,mapper); MITK_TEST_CONDITION( mapper == dataNode->GetMapper(1), "Testing if a UnstructuredGridMapper2D was set correctly" ) MITK_TEST_CONDITION( dataNode == mapper->GetDataNode(), "Testing if the mapper returns the right DataNode" ) - mapper = mitk::LineMapper2D::New(); + /*mapper = mitk::LineMapper2D::New(); dataNode->SetMapper(1,mapper); MITK_TEST_CONDITION( mapper == dataNode->GetMapper(1), "Testing if a LineMapper2D was set correctly" ) MITK_TEST_CONDITION( dataNode == mapper->GetDataNode(), "Testing if the mapper returns the right DataNode" ) mapper = mitk::SplineMapper2D::New(); dataNode->SetMapper(1,mapper); MITK_TEST_CONDITION( mapper == dataNode->GetMapper(1), "Testing if a SplineMapper2D was set correctly" ) MITK_TEST_CONDITION( dataNode == mapper->GetDataNode(), "Testing if the mapper returns the right DataNode" ) - +*/ mapper = mitk::MeshVtkMapper3D::New(); dataNode->SetMapper(1,mapper); MITK_TEST_CONDITION( mapper == dataNode->GetMapper(1), "Testing if a MeshVtkMapper3D was set correctly" ) MITK_TEST_CONDITION( dataNode == mapper->GetDataNode(), "Testing if the mapper returns the right DataNode" ) mapper = mitk::UnstructuredGridVtkMapper3D::New(); dataNode->SetMapper(1,mapper); MITK_TEST_CONDITION( mapper == dataNode->GetMapper(1), "Testing if a UnstructuredGridVtkMapper3D was set correctly" ) MITK_TEST_CONDITION( dataNode == mapper->GetDataNode(), "Testing if the mapper returns the right DataNode" ) //linker error //mapper = mitk::LineVtkMapper3D::New(); //dataNode->SetMapper(1,mapper); //MITK_TEST_CONDITION( mapper == dataNode->GetMapper(1), "Testing if a LineVtkMapper3D was set correctly" ) //MITK_TEST_CONDITION( dataNode == mapper->GetDataNode(), "Testing if the mapper returns the right DataNode" ) mapper = mitk::SplineVtkMapper3D::New(); dataNode->SetMapper(1,mapper); MITK_TEST_CONDITION( mapper == dataNode->GetMapper(1), "Testing if a SplineVtkMapper3D was set correctly" ) MITK_TEST_CONDITION( dataNode == mapper->GetDataNode(), "Testing if the mapper returns the right DataNode" ) } static void TestInteractorSetting(mitk::DataNode::Pointer dataNode) { //this method tests the SetInteractor() and GetInteractor methods //the Interactor base class calls the DataNode->SetInteractor method mitk::Interactor::Pointer interactor; MITK_TEST_CONDITION( interactor == dataNode->GetInteractor(), "Testing if a NULL pointer was set correctly (Interactor)" ) interactor = mitk::ConnectPointsInteractor::New("AffineInteractions click to select", dataNode); MITK_TEST_CONDITION( interactor == dataNode->GetInteractor(), "Testing if a ConnectPointsInteractor was set correctly" ) interactor = mitk::PointInteractor::New("AffineInteractions click to select", dataNode); MITK_TEST_CONDITION( interactor == dataNode->GetInteractor(), "Testing if a PointInteractor was set correctly" ) interactor = mitk::PointSelectorInteractor::New("AffineInteractions click to select", dataNode); MITK_TEST_CONDITION( interactor == dataNode->GetInteractor(), "Testing if a PointSelectorInteractor was set correctly" ) interactor = mitk::SeedsInteractor::New("AffineInteractions click to select", dataNode); MITK_TEST_CONDITION( interactor == dataNode->GetInteractor(), "Testing if a SeedsInteractor was set correctly" ) interactor = mitk::DisplayPointSetInteractor::New("AffineInteractions click to select", dataNode); MITK_TEST_CONDITION( interactor == dataNode->GetInteractor(), "Testing if a DisplayPointSetInteractor was set correctly" ) } }; int mitkDataNodeExtTest(int /* argc */, char* /*argv*/[]) { // always start with this! MITK_TEST_BEGIN("DataNode") // Global interaction must(!) be initialized mitk::GlobalInteraction::GetInstance()->Initialize("global"); // let's create an object of our class mitk::DataNode::Pointer myDataNode = mitk::DataNode::New(); // first test: did this work? // using MITK_TEST_CONDITION_REQUIRED makes the test stop after failure, since // it makes no sense to continue without an object. MITK_TEST_CONDITION_REQUIRED(myDataNode.IsNotNull(),"Testing instantiation") //test setData() Method mitkDataNodeExtTestClass::TestDataSetting(myDataNode); mitkDataNodeExtTestClass::TestMapperSetting(myDataNode); //note, that no data is set to the dataNode mitkDataNodeExtTestClass::TestInteractorSetting(myDataNode); // write your own tests here and use the macros from mitkTestingMacros.h !!! // do not write to std::cout and do not return from this function yourself! // always end with this! MITK_TEST_END() }