Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes

mitk::Geometry2DDataMapper2D Class Reference
[Mapper Classes]

OpenGL-based mapper to display a Geometry2D in a 2D window. More...

#include <mitkGeometry2DDataMapper2D.h>

Inheritance diagram for mitk::Geometry2DDataMapper2D:
Inheritance graph
[legend]
Collaboration diagram for mitk::Geometry2DDataMapper2D:
Collaboration graph
[legend]

List of all members.

Public Types

typedef Geometry2DDataMapper2D Self
typedef GLMapper2D Superclass
typedef itk::SmartPointer< SelfPointer
typedef itk::SmartPointer
< const Self
ConstPointer

Public Member Functions

virtual const char * GetClassName () const
const Geometry2DDataGetInput ()
 Get the Geometry2DData to map.
virtual void Paint (BaseRenderer *renderer)
 Do the painting into the renderer.
virtual void SetDatastorageAndGeometryBaseNode (mitk::DataStorage::Pointer ds, mitk::DataNode::Pointer parent)
virtual void ApplyProperties (BaseRenderer *renderer)

Static Public Member Functions

static Pointer New ()

Protected Types

typedef std::vector< DataNode * > NodesVectorType

Protected Member Functions

 Geometry2DDataMapper2D ()
virtual ~Geometry2DDataMapper2D ()
virtual void GenerateData ()
 Generate the data needed for rendering (independent of a specific renderer)
void DrawOrientationArrow (Point2D &outerPoint, Point2D &innerPoint, const PlaneGeometry *planeGeometry, const PlaneGeometry *rendererPlaneGeometry, const DisplayGeometry *displayGeometry, bool positiveOrientation=true)

Protected Attributes

SurfaceGLMapper2D::Pointer m_SurfaceMapper
mitk::WeakPointer
< mitk::DataStorage
m_DataStorage
 DataStorage that will be searched for sub nodes.
DataNode::Pointer m_ParentNode
 parent node that will be used to search for sub nodes
NodesVectorType m_OtherGeometry2Ds
bool m_RenderOrientationArrows
bool m_ArrowOrientationPositive

Detailed Description

OpenGL-based mapper to display a Geometry2D in a 2D window.

Currently implemented for mapping on PlaneGeometry. The result is normally a line. An important usage of this class is to show the orientation of the slices displayed in other 2D windows.

Properties that can be set and influence the Geometry2DDataMapper2D are:

Definition at line 49 of file mitkGeometry2DDataMapper2D.h.


Member Typedef Documentation

typedef itk::SmartPointer<const Self> mitk::Geometry2DDataMapper2D::ConstPointer

Reimplemented from mitk::Mapper2D.

Definition at line 53 of file mitkGeometry2DDataMapper2D.h.

typedef std::vector<DataNode*> mitk::Geometry2DDataMapper2D::NodesVectorType [protected]

Definition at line 89 of file mitkGeometry2DDataMapper2D.h.

typedef itk::SmartPointer<Self> mitk::Geometry2DDataMapper2D::Pointer

Reimplemented from mitk::Mapper2D.

Definition at line 53 of file mitkGeometry2DDataMapper2D.h.

Reimplemented from mitk::Mapper2D.

Definition at line 53 of file mitkGeometry2DDataMapper2D.h.

Reimplemented from mitk::Mapper2D.

Definition at line 53 of file mitkGeometry2DDataMapper2D.h.


Constructor & Destructor Documentation

mitk::Geometry2DDataMapper2D::Geometry2DDataMapper2D (  ) [protected]
mitk::Geometry2DDataMapper2D::~Geometry2DDataMapper2D (  ) [protected, virtual]

Definition at line 41 of file mitkGeometry2DDataMapper2D.cpp.

{
}

Member Function Documentation

void mitk::Geometry2DDataMapper2D::ApplyProperties ( BaseRenderer renderer ) [virtual]

Applies properties specific to this mapper

Reimplemented from mitk::GLMapper2D.

Definition at line 408 of file mitkGeometry2DDataMapper2D.cpp.

References mitk::PlaneOrientationProperty::GetPlaneDecoration(), mitk::PlaneOrientationProperty::PLANE_DECORATION_NEGATIVE_ORIENTATION, and mitk::PlaneOrientationProperty::PLANE_DECORATION_POSITIVE_ORIENTATION.

{
  Superclass::ApplyProperties(renderer);

  PlaneOrientationProperty* decorationProperty;
  this->GetDataNode()->GetProperty( decorationProperty, "decoration", renderer );
  if ( decorationProperty != NULL )
  {
    if ( decorationProperty->GetPlaneDecoration() == 
      PlaneOrientationProperty::PLANE_DECORATION_POSITIVE_ORIENTATION )
    {
      m_RenderOrientationArrows = true;
      m_ArrowOrientationPositive = true;
    }
    else if ( decorationProperty->GetPlaneDecoration() == 
      PlaneOrientationProperty::PLANE_DECORATION_NEGATIVE_ORIENTATION )
    {
      m_RenderOrientationArrows = true;
      m_ArrowOrientationPositive = false;
    }
    else
    {
      m_RenderOrientationArrows = false;
    }
  }
}
void mitk::Geometry2DDataMapper2D::DrawOrientationArrow ( Point2D &  outerPoint,
Point2D &  innerPoint,
const PlaneGeometry planeGeometry,
const PlaneGeometry rendererPlaneGeometry,
const DisplayGeometry displayGeometry,
bool  positiveOrientation = true 
) [protected]
void mitk::Geometry2DDataMapper2D::GenerateData (  ) [protected, virtual]

Generate the data needed for rendering (independent of a specific renderer)

Reimplemented from mitk::Mapper.

Definition at line 52 of file mitkGeometry2DDataMapper2D.cpp.

References mitk::Geometry2DData::GetGeometry2D(), and mitk::NodePredicateDataType::New().

{
  // collect all Geometry2DDatas accessible from the DataStorage
  m_OtherGeometry2Ds.clear();
  if (m_DataStorage.IsNull())
    return;
  
  mitk::NodePredicateDataType::Pointer p = mitk::NodePredicateDataType::New("Geometry2DData");
  mitk::DataStorage::SetOfObjects::ConstPointer all = m_DataStorage->GetDerivations(m_ParentNode, p, false);
  for (mitk::DataStorage::SetOfObjects::ConstIterator it = all->Begin(); it != all->End(); ++it)
  {
    if(it->Value().IsNull())
      continue;

    BaseData* data = it->Value()->GetData();
    if (data == NULL)
      continue;

    Geometry2DData* geometry2dData = dynamic_cast<Geometry2DData*>(data);
    if(geometry2dData == NULL)
      continue;

    PlaneGeometry* planegeometry = dynamic_cast<PlaneGeometry*>(geometry2dData->GetGeometry2D());
    if (planegeometry != NULL)
      m_OtherGeometry2Ds.push_back(it->Value());
  }
}
virtual const char* mitk::Geometry2DDataMapper2D::GetClassName (  ) const [virtual]

Reimplemented from mitk::Mapper2D.

const mitk::Geometry2DData * mitk::Geometry2DDataMapper2D::GetInput ( void   )

Get the Geometry2DData to map.

Definition at line 46 of file mitkGeometry2DDataMapper2D.cpp.

{
  return static_cast<const Geometry2DData * > ( GetData() );
}
static Pointer mitk::Geometry2DDataMapper2D::New (  ) [static]
void mitk::Geometry2DDataMapper2D::Paint ( BaseRenderer renderer ) [virtual]

Do the painting into the renderer.

Implements mitk::GLMapper2D.

Definition at line 81 of file mitkGeometry2DDataMapper2D.cpp.

References mitk::Line< TCoordRep, NPointDimension >::BoxLineIntersection(), mitk::Geometry3D::GetBoundingBox(), mitk::BaseRenderer::GetCurrentWorldGeometry2D(), mitk::Line< TCoordRep, NPointDimension >::GetDirection(), mitk::BaseRenderer::GetDisplayGeometry(), mitk::Geometry3D::GetImageGeometry(), mitk::Geometry3D::GetIndexToWorldTransform(), mitk::Line< TCoordRep, NPointDimension >::GetPoint(), mitk::Line< TCoordRep, NPointDimension >::GetPoint1(), mitk::Geometry2D::GetReferenceGeometry(), GL_LINES, glBegin(), glEnd(), glVertex2f(), mitk::PlaneGeometry::IntersectionLine(), mitk::Geometry2D::Map(), mitk::SurfaceGLMapper2D::New(), mitk::SmartPointerProperty::New(), mitk::Geometry2DDataToSurfaceFilter::New(), mitk::Line< TCoordRep, NPointDimension >::SetPoints(), QuadProgPP::sort(), QuadProgPP::t(), mitk::Line< TCoordRep, NPointDimension >::Transform(), and mitk::DisplayGeometry::WorldToDisplay().

{
  if ( !this->IsVisible(renderer) )
  {
    return;
  }
  
  Geometry2DData::Pointer input = const_cast< Geometry2DData * >(this->GetInput());

  // intersecting with ourself?
  if ( input.IsNull() || (this->GetInput()->GetGeometry2D() == 
       renderer->GetCurrentWorldGeometry2D()) )
  {
    return; // do nothing!
  }
  
  const PlaneGeometry *inputPlaneGeometry = 
    dynamic_cast< const PlaneGeometry * >( input->GetGeometry2D() );

  const PlaneGeometry *worldPlaneGeometry =
    dynamic_cast< const PlaneGeometry* >( 
      renderer->GetCurrentWorldGeometry2D() );

  if ( worldPlaneGeometry && inputPlaneGeometry 
    && inputPlaneGeometry->GetReferenceGeometry() )
  {
    DisplayGeometry *displayGeometry = renderer->GetDisplayGeometry();
    assert( displayGeometry );

    const Geometry3D *referenceGeometry = 
      inputPlaneGeometry->GetReferenceGeometry();

    // calculate intersection of the plane data with the border of the 
    // world geometry rectangle
    Point2D lineFrom, lineTo;
    
    typedef Geometry3D::TransformType TransformType;
    const TransformType *transform = dynamic_cast< const TransformType * >(
      referenceGeometry->GetIndexToWorldTransform() );

    TransformType::Pointer inverseTransform = TransformType::New();
    transform->GetInverse( inverseTransform );

    Line3D crossLine, otherCrossLine;

    // Calculate the intersection line of the input plane with the world plane
    if ( worldPlaneGeometry->IntersectionLine( 
          inputPlaneGeometry, crossLine ) )
    {
      BoundingBox::PointType boundingBoxMin, boundingBoxMax;
      boundingBoxMin = referenceGeometry->GetBoundingBox()->GetMinimum();
      boundingBoxMax = referenceGeometry->GetBoundingBox()->GetMaximum();
      if(referenceGeometry->GetImageGeometry())
      {
        for(unsigned int i = 0; i < 3; ++i)
        {
          boundingBoxMin[i]-=0.5;
          boundingBoxMax[i]-=0.5;
        }
      }

      crossLine.Transform( *inverseTransform );
      Point3D point1, point2;

      // Then, clip this line with the (transformed) bounding box of the 
      // reference geometry.
      if ( crossLine.BoxLineIntersection(
        boundingBoxMin[0], boundingBoxMin[1], boundingBoxMin[2],
        boundingBoxMax[0], boundingBoxMax[1], boundingBoxMax[2],
        crossLine.GetPoint(), crossLine.GetDirection(),
        point1, point2 ) == 2 )
      {
        // Transform the resulting line start and end points into display
        // coordinates.
        worldPlaneGeometry->Map( 
          transform->TransformPoint( point1 ), lineFrom );
        worldPlaneGeometry->Map( 
          transform->TransformPoint( point2 ), lineTo );

        Line< ScalarType, 2 > line, otherLine;
        line.SetPoints( lineFrom, lineTo );

        displayGeometry->WorldToDisplay( lineFrom, lineFrom );
        displayGeometry->WorldToDisplay( lineTo, lineTo );

        ScalarType lengthInDisplayUnits = (lineTo - lineFrom).GetNorm();

        // lineParams stores the individual segments of the line, which are
        // separated by a gap each (to mark the intersection with another
        // displayed line)
        std::vector< ScalarType > lineParams;
        lineParams.reserve( m_OtherGeometry2Ds.size() + 2 );
        lineParams.push_back( 0.0 );
        lineParams.push_back( 1.0 );

        Vector2D d, dOrth;
        
        // Now iterate through all other lines displayed in this window and
        // calculate the positions of intersection with the line to be
        // rendered; these positions will be stored in lineParams to form a
        // gap afterwards.
        NodesVectorType::iterator otherPlanesIt = m_OtherGeometry2Ds.begin();
        NodesVectorType::iterator otherPlanesEnd = m_OtherGeometry2Ds.end();
        while ( otherPlanesIt != otherPlanesEnd )
        {
          PlaneGeometry *otherPlane = static_cast< PlaneGeometry * >(
            static_cast< Geometry2DData * >(
              (*otherPlanesIt)->GetData() )->GetGeometry2D() );

          // Just as with the original line, calculate the intersaction with
          // the world geometry...
          if ( (otherPlane != inputPlaneGeometry)
            && worldPlaneGeometry->IntersectionLine( 
                 otherPlane, otherCrossLine ) )
          {
            // ... and clip the resulting line segment with the reference 
            // geometry bounding box.
            otherCrossLine.Transform( *inverseTransform );
            if ( otherCrossLine.BoxLineIntersection(
              boundingBoxMin[0], boundingBoxMin[1], boundingBoxMin[2],
              boundingBoxMax[0], boundingBoxMax[1], boundingBoxMax[2],
              otherCrossLine.GetPoint(), otherCrossLine.GetDirection(),
              point1, point2 ) == 2 )
            {
              worldPlaneGeometry->Map( 
                transform->TransformPoint( point1 ), lineFrom );
              worldPlaneGeometry->Map( 
                transform->TransformPoint( point2 ), lineTo );

              // By means of the dot product, calculate the gap position as
              // parametric value in the range [0, 1]
              otherLine.SetPoints( lineFrom, lineTo );
              d = otherLine.GetDirection();
              dOrth[0] = -d[1]; dOrth[1] = d[0];
              
              ScalarType t, norm; 
              t = ( otherLine.GetPoint1() - line.GetPoint1() ) * dOrth;
              norm = line.GetDirection() * dOrth;

              if ( fabs( norm ) > eps )
              {
                t /= norm;
                if ( (t > 0.0) && (t < 1.0) )
                {
                  lineParams.push_back(t);
                }
              }
            }
          }
          ++otherPlanesIt;
        }

        // Apply color and opacity read from the PropertyList.
        this->ApplyProperties( renderer );

        ScalarType gapSizeInPixel = 10.0;
        ScalarType gapSizeInParamUnits = 
          1.0 / lengthInDisplayUnits * gapSizeInPixel;

        std::sort( lineParams.begin(), lineParams.end() );

        Point2D p1, p2;
        ScalarType p1Param, p2Param; 
        
        p1Param = lineParams[0];
        p1 = line.GetPoint( p1Param );
        displayGeometry->WorldToDisplay( p1, p1 );

        // Iterate over all line segments and display each, with a gap
        // inbetween.
        unsigned int i, preLastLineParam = lineParams.size() - 1;
        for ( i = 1; i < preLastLineParam; ++i )
        {
          p2Param = lineParams[i] - gapSizeInParamUnits * 0.5;
          p2 = line.GetPoint( p2Param );

          if ( p2Param > p1Param )
          {
            // Convert intersection points (until now mm) to display 
            // coordinates (units).
            displayGeometry->WorldToDisplay( p2, p2 );

            // draw
            glBegin (GL_LINES);
            glVertex2f(p1[0],p1[1]);
            glVertex2f(p2[0],p2[1]);
            glEnd ();

            if ( (i == 1) && (m_RenderOrientationArrows) )
            {
              // Draw orientation arrow for first line segment
              this->DrawOrientationArrow( p1, p2, 
                inputPlaneGeometry, worldPlaneGeometry, displayGeometry,
                m_ArrowOrientationPositive );
            }
          }

          p1Param = p2Param + gapSizeInParamUnits;
          p1 = line.GetPoint( p1Param );
          displayGeometry->WorldToDisplay( p1, p1 );
        }

        // Draw last line segment
        p2Param = lineParams[i];
        p2 = line.GetPoint( p2Param );
        displayGeometry->WorldToDisplay( p2, p2 );
        glBegin( GL_LINES );
        glVertex2f( p1[0], p1[1] );
        glVertex2f( p2[0], p2[1] );
        glEnd();


        // Draw orientation arrows
        if ( m_RenderOrientationArrows )
        {
          this->DrawOrientationArrow( p2, p1, 
            inputPlaneGeometry, worldPlaneGeometry, displayGeometry,
            m_ArrowOrientationPositive );
          if ( preLastLineParam < 2 )
          {
            // If we only have one line segment, draw other arrow, too
            this->DrawOrientationArrow( p1, p2, 
              inputPlaneGeometry, worldPlaneGeometry, displayGeometry,
              m_ArrowOrientationPositive );
          }
        }
      }
    }
  }
  else
  {
    Geometry2DDataToSurfaceFilter::Pointer surfaceCreator;
    SmartPointerProperty::Pointer surfacecreatorprop;
    surfacecreatorprop = dynamic_cast< SmartPointerProperty * >(
      GetDataNode()->GetProperty(
        "surfacegeometry", renderer));

    if( (surfacecreatorprop.IsNull()) || 
        (surfacecreatorprop->GetSmartPointer().IsNull()) ||
        ((surfaceCreator = dynamic_cast< Geometry2DDataToSurfaceFilter * >(
          surfacecreatorprop->GetSmartPointer().GetPointer())).IsNull())
      )
    {
      surfaceCreator = Geometry2DDataToSurfaceFilter::New();
      surfacecreatorprop = SmartPointerProperty::New(surfaceCreator);
      surfaceCreator->PlaceByGeometryOn();
      GetDataNode()->SetProperty( "surfacegeometry", surfacecreatorprop );
    }
    
    surfaceCreator->SetInput( input );

    // Clip the Geometry2D with the reference geometry bounds (if available)
    if ( input->GetGeometry2D()->HasReferenceGeometry() )
    {
      surfaceCreator->SetBoundingBox(
        input->GetGeometry2D()->GetReferenceGeometry()->GetBoundingBox()
      );
    }

    int res;
    bool usegeometryparametricbounds = true;
    if ( GetDataNode()->GetIntProperty("xresolution", res, renderer))
    {
      surfaceCreator->SetXResolution(res);
      usegeometryparametricbounds=false;        
    }
    if (GetDataNode()->GetIntProperty("yresolution", res, renderer))
    {
      surfaceCreator->SetYResolution(res);
      usegeometryparametricbounds=false;        
    }
    surfaceCreator->SetUseGeometryParametricBounds(usegeometryparametricbounds);

    // Calculate the surface of the Geometry2D
    surfaceCreator->Update();
    
    if (m_SurfaceMapper.IsNull())
    {
      m_SurfaceMapper=SurfaceGLMapper2D::New();
    }
    m_SurfaceMapper->SetSurface(surfaceCreator->GetOutput());
    m_SurfaceMapper->SetDataNode(GetDataNode());
    
    m_SurfaceMapper->Paint(renderer);
  }
}
void mitk::Geometry2DDataMapper2D::SetDatastorageAndGeometryBaseNode ( mitk::DataStorage::Pointer  ds,
mitk::DataNode::Pointer  parent 
) [virtual]

Definition at line 436 of file mitkGeometry2DDataMapper2D.cpp.

{
  if (ds.IsNotNull())
  {
    m_DataStorage = ds;
  }
  if (parent.IsNotNull())
  {
    m_ParentNode = parent;
  }
}

Member Data Documentation

Definition at line 93 of file mitkGeometry2DDataMapper2D.h.

DataStorage that will be searched for sub nodes.

Definition at line 86 of file mitkGeometry2DDataMapper2D.h.

Definition at line 90 of file mitkGeometry2DDataMapper2D.h.

parent node that will be used to search for sub nodes

Definition at line 87 of file mitkGeometry2DDataMapper2D.h.

Definition at line 92 of file mitkGeometry2DDataMapper2D.h.

Definition at line 84 of file mitkGeometry2DDataMapper2D.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines