Commit 4e47a215 authored by Ken Martin's avatar Ken Martin
Browse files

ENH: advanced actor code

parent 750c6238
......@@ -20,6 +20,7 @@ vtkFloatTCoords \
vtkFloatTensors \
vtkFloatVectors \
vtkImplicitFunctionCollection \
vtkPropCollection \
vtkTransformCollection \
vtkVersion
......@@ -32,9 +33,7 @@ vtkImplicitFunction \
vtkImageCache \
vtkImageSource \
vtkLocator \
vtkMapper2D \
vtkPointSet \
vtkProp2D \
vtkViewport \
vtkWindow
......@@ -71,6 +70,7 @@ vtkLine \
vtkLogLookupTable \
vtkLongArray \
vtkLookupTable \
vtkMapper2D \
vtkMath \
vtkMatrix4x4 \
vtkMultiThreader \
......@@ -88,6 +88,7 @@ vtkPolyVertex \
vtkPolygon \
vtkPriorityQueue \
vtkProcessObject \
vtkProp \
vtkProperty2D \
vtkPyramid \
vtkQuad \
......
......@@ -48,11 +48,21 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
vtkActor2D::vtkActor2D()
{
this->Mapper = (vtkMapper2D*) NULL;
this->LayerNumber = 0;
this->Property = (vtkProperty2D*) NULL;
this->PositionCoordinate = vtkCoordinate::New();
this->PositionCoordinate->SetCoordinateSystem(VTK_VIEWPORT);
}
// Destroy an actor2D.
vtkActor2D::~vtkActor2D()
{
if (this->Property)
{
this->Property->UnRegister(this);
}
this->PositionCoordinate->Delete();
this->PositionCoordinate = NULL;
if (this->Mapper != NULL)
{
this->Mapper->UnRegister(this);
......@@ -61,9 +71,9 @@ vtkActor2D::~vtkActor2D()
}
// Renders an actor2D's property and then it's mapper.
void vtkActor2D::Render (vtkViewport* viewport)
void vtkActor2D::RenderOverlay(vtkViewport* viewport)
{
vtkDebugMacro(<< "vtkActor2D::Render");
vtkDebugMacro(<< "vtkActor2D::RenderOverlay");
if (!this->Property)
{
......@@ -80,9 +90,53 @@ void vtkActor2D::Render (vtkViewport* viewport)
return;
}
vtkDebugMacro(<<"vtkActor2D::Render - Rendering mapper");
this->Mapper->Render(viewport, this);
this->Mapper->RenderOverlay(viewport, this);
}
// Renders an actor2D's property and then it's mapper.
void vtkActor2D::RenderOpaqueGeometry(vtkViewport* viewport)
{
vtkDebugMacro(<< "vtkActor2D::RenderOpaqueGeometry");
if (!this->Property)
{
vtkDebugMacro(<< "vtkActor2D::Render - Creating Property2D");
// Force creation of default property
this->GetProperty();
}
this->Property->Render(viewport);
if (!this->Mapper)
{
vtkErrorMacro(<< "vtkActor2D::Render - No mapper set");
return;
}
this->Mapper->RenderOpaqueGeometry(viewport, this);
}
// Renders an actor2D's property and then it's mapper.
void vtkActor2D::RenderTranslucentGeometry(vtkViewport* viewport)
{
vtkDebugMacro(<< "vtkActor2D::RenderTranslucentGeometry");
if (!this->Property)
{
vtkDebugMacro(<< "vtkActor2D::Render - Creating Property2D");
// Force creation of default property
this->GetProperty();
}
this->Property->Render(viewport);
if (!this->Mapper)
{
vtkErrorMacro(<< "vtkActor2D::Render - No mapper set");
return;
}
this->Mapper->RenderTranslucentGeometry(viewport, this);
}
void vtkActor2D::SetMapper(vtkMapper2D *mapper)
......@@ -103,10 +157,57 @@ void vtkActor2D::SetMapper(vtkMapper2D *mapper)
}
void vtkActor2D::PrintSelf(ostream& os, vtkIndent indent)
unsigned long int vtkActor2D::GetMTime()
{
this->vtkProp2D::PrintSelf(os,indent);
unsigned long mTime=this->vtkObject::GetMTime();
unsigned long time;
time = this->PositionCoordinate->GetMTime();
mTime = ( time > mTime ? time : mTime );
if ( this->Property != NULL )
{
time = this->Property->GetMTime();
mTime = ( time > mTime ? time : mTime );
}
return mTime;
}
// Set the Prop2D's position in display coordinates.
void vtkActor2D::SetDisplayPosition(int XPos, int YPos)
{
this->PositionCoordinate->SetCoordinateSystem(VTK_DISPLAY);
this->PositionCoordinate->SetValue((float)XPos,(float)YPos,0.0);
}
// Returns an Prop2D's property2D. Creates a property if one
// doesn't already exist.
vtkProperty2D *vtkActor2D::GetProperty()
{
if (this->Property == NULL)
{
this->Property = vtkProperty2D::New();
this->Property->Register(this);
this->Property->Delete();
this->Modified();
}
return this->Property;
}
void vtkActor2D::PrintSelf(ostream& os, vtkIndent indent)
{
this->vtkProp::PrintSelf(os,indent);
os << indent << "Layer Number: " << this->LayerNumber << "\n";
os << indent << "PositionCoordinate: " << this->PositionCoordinate << "\n";
this->PositionCoordinate->PrintSelf(os, indent.GetNextIndent());
os << indent << "Property: " << this->Property << "\n";
if (this->Property)
{
this->Property->PrintSelf(os, indent.GetNextIndent());
}
os << indent << "Mapper: " << this->Mapper << "\n";
if (this->Mapper)
{
......
......@@ -46,17 +46,29 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
// a vtkMapper2D object which does the rendering.
// .SECTION See Also
// vtkProp2D vtkMapper2D vtkProperty2D
// vtkProp vtkMapper2D vtkProperty2D
#ifndef __vtkActor2D_h
#define __vtkActor2D_h
#include "vtkProp2D.h"
#include "vtkProp.h"
#include "vtkCoordinate.h"
#include "vtkProperty2D.h"
class vtkMapper2D;
class VTK_EXPORT vtkActor2D : public vtkProp2D
class VTK_EXPORT vtkActor2D : public vtkProp
{
public:
static vtkActor2D* New() {return new vtkActor2D;};
void PrintSelf(ostream& os, vtkIndent indent);
const char *GetClassName() {return "vtkActor2D";};
// Description:
// Support the standard render methods.
virtual void RenderOverlay(vtkViewport *viewport);
virtual void RenderOpaqueGeometry(vtkViewport *viewport);
virtual void RenderTranslucentGeometry(vtkViewport *viewport);
// Description:
// Creates an actor2D with the following defaults:
// position -1, -1 (view coordinates)
......@@ -66,26 +78,47 @@ public:
// Description:
// Destroy an actor2D.
~vtkActor2D();
static vtkActor2D* New() {return new vtkActor2D;};
void PrintSelf(ostream& os, vtkIndent indent);
const char *GetClassName() {return "vtkActor2D";};
// Description:
// Renders an actor2D's property and then it's mapper.
virtual void Render(vtkViewport *viewport);
// Description:
// Set/Get the vtkMapper2D which defines the data to be drawn.
void SetMapper(vtkMapper2D *mapper);
vtkGetObjectMacro(Mapper, vtkMapper2D);
// Description:
// Set/Get the layer number in the overlay planes into which to render.
vtkSetMacro(LayerNumber, int);
vtkGetMacro(LayerNumber, int);
// Description:
// Returns an Prop2D's property2D. Creates a property if one
// doesn't already exist.
vtkProperty2D* GetProperty();
// Description:
// Set this vtkProp's vtkProperty2D.
vtkSetObjectMacro(Property, vtkProperty2D);
// Description:
// Get the PositionCoordinate instance of vtkCoordinate.
// This is used for for complicated or relative positioning.
vtkViewportCoordinateMacro(Position);
// Description:
// Set the Prop2D's position in display coordinates.
void SetDisplayPosition(int,int);
// Description:
// Return this objects MTime.
unsigned long GetMTime();
protected:
vtkMapper2D *Mapper;
int LayerNumber;
vtkProperty2D *Property;
vtkCoordinate *PositionCoordinate;
};
#endif
......@@ -57,7 +57,7 @@ vtkActor2DCollection::~vtkActor2DCollection()
}
// Sort and then render the collection of 2D actors.
void vtkActor2DCollection::Render(vtkViewport* viewport)
void vtkActor2DCollection::RenderOverlay(vtkViewport* viewport)
{
if (this->NumberOfItems != 0)
{
......@@ -68,8 +68,8 @@ void vtkActor2DCollection::Render(vtkViewport* viewport)
{
// Make sure that the actor is visible before rendering
if (tempActor->GetVisibility() == 1)
{
tempActor->Render(viewport);
{
tempActor->RenderOverlay(viewport);
}
}
}
......
......@@ -84,7 +84,7 @@ class VTK_EXPORT vtkActor2DCollection : public vtkCollection
// Description:
// Sort and then render the collection of 2D actors.
void Render(vtkViewport* viewport);
void RenderOverlay(vtkViewport* viewport);
protected:
......
......@@ -49,7 +49,6 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#ifndef __vtkMapper2D_h
#define __vtkMapper2D_h
#include "vtkObject.h"
#include "vtkViewport.h"
#include "vtkWindow.h"
#include "vtkActor2D.h"
......@@ -57,8 +56,13 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
class VTK_EXPORT vtkMapper2D : public vtkObject
{
public:
static vtkMapper2D* New() {return new vtkMapper2D;};
void PrintSelf(ostream& os, vtkIndent indent);
virtual void Render(vtkViewport* viewport, vtkActor2D* actor) = 0;
virtual void RenderOverlay(vtkViewport* viewport, vtkActor2D* actor) {};
virtual void RenderOpaqueGeometry(vtkViewport* viewport,
vtkActor2D* actor) {};
virtual void RenderTranslucentGeometry(vtkViewport* viewport,
vtkActor2D* actor) {};
protected:
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkProp2D.cxx
Module: vtkProp.cxx
Language: C++
Date: $Date$
Version: $Revision$
Thanks: Thanks to Matt Turek who developed this class.
Copyright (c) 1993-1998 Ken Martin, Will Schroeder, Bill Lorensen.
......@@ -38,85 +37,22 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
=========================================================================*/
#include "vtkProp2D.h"
#include "vtkProperty2D.h"
#include "vtkProp.h"
// Creates an Prop2D with the following defaults:
// position -1, -1 (view coordinates), layer 0, and visibility on.
vtkProp2D::vtkProp2D()
// Creates an Prop with the following defaults: visibility on.
vtkProp::vtkProp()
{
this->LayerNumber = 0;
this->Visibility = 1; // ON
this->Property = (vtkProperty2D*) NULL;
this->PositionCoordinate = vtkCoordinate::New();
this->PositionCoordinate->SetCoordinateSystem(VTK_VIEWPORT);
this->AllocatedRenderTime = 10.0;
}
// Destroy an Prop2D. If the Prop2D created it's own
// property, that property is deleted.
vtkProp2D::~vtkProp2D()
{
if (this->Property)
{
this->Property->UnRegister(this);
}
this->PositionCoordinate->Delete();
this->PositionCoordinate = NULL;
}
// Set the Prop2D's position in display coordinates.
void vtkProp2D::SetDisplayPosition(int XPos, int YPos)
{
this->PositionCoordinate->SetCoordinateSystem(VTK_DISPLAY);
this->PositionCoordinate->SetValue((float)XPos,(float)YPos,0.0);
}
// Returns an Prop2D's property2D. Creates a property if one
// doesn't already exist.
vtkProperty2D *vtkProp2D::GetProperty()
{
if (this->Property == NULL)
{
this->Property = vtkProperty2D::New();
this->Property->Register(this);
this->Property->Delete();
this->Modified();
}
return this->Property;
}
unsigned long int vtkProp2D::GetMTime()
{
unsigned long mTime=this->vtkObject::GetMTime();
unsigned long time;
time = this->PositionCoordinate->GetMTime();
mTime = ( time > mTime ? time : mTime );
if ( this->Property != NULL )
{
time = this->Property->GetMTime();
mTime = ( time > mTime ? time : mTime );
}
return mTime;
}
void vtkProp2D::PrintSelf(ostream& os, vtkIndent indent)
void vtkProp::PrintSelf(ostream& os, vtkIndent indent)
{
this->vtkObject::PrintSelf(os,indent);
os << indent << "Layer Number: " << this->LayerNumber << "\n";
os << indent << "AllocatedRenderTime: "
<< this->AllocatedRenderTime << endl;
os << indent << "Visibility: " << (this->Visibility ? "On\n" : "Off\n");
os << indent << "PositionCoordinate: " << this->PositionCoordinate << "\n";
this->PositionCoordinate->PrintSelf(os, indent.GetNextIndent());
os << indent << "Property: " << this->Property << "\n";
if (this->Property)
{
this->Property->PrintSelf(os, indent.GetNextIndent());
}
}
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkProp.h
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 1993-1998 Ken Martin, Will Schroeder, Bill Lorensen.
This software is copyrighted by Ken Martin, Will Schroeder and Bill Lorensen.
The following terms apply to all files associated with the software unless
explicitly disclaimed in individual files. This copyright specifically does
not apply to the related textbook "The Visualization Toolkit" ISBN
013199837-4 published by Prentice Hall which is covered by its own copyright.
The authors hereby grant permission to use, copy, and distribute this
software and its documentation for any purpose, provided that existing
copyright notices are retained in all copies and that this notice is included
verbatim in any distributions. Additionally, the authors grant permission to
modify this software and its documentation for any purpose, provided that
such modifications are not distributed without the explicit consent of the
authors and that existing copyright notices are retained in all copies. Some
of the algorithms implemented by this software are patented, observe all
applicable patent law.
IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN
"AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
=========================================================================*/
// .NAME vtkProp - abstract superclass for all actors, volumes and annotations
// .SECTION Description
// vtkProp is an abstract superclass for actor type objects. Instances of
// vtkProp may respond to RenderGeometry, RenderVolume, and RenderPostSwap
// calls and may repond to more than one.
//
// .SECTION See Also
// vtkActor2D vtkActor vtkVolume
#ifndef __vtkProp_h
#define __vtkProp_h
#include "vtkObject.h"
class vtkViewport;
class vtkActorCollection;
class vtkActor2DCollection;
class vtkVolumeCollection;
class VTK_EXPORT vtkProp : public vtkObject
{
public:
static vtkProp* New() {return new vtkProp;};
void PrintSelf(ostream& os, vtkIndent indent);
const char *GetClassName() {return "vtkProp";};
// Description:
// Creates an Prop with visibility on.
vtkProp();
// Description:
// All concrete subclasses must be able to render themselves.
// There are five key render methods in vtk and they correspond
// to five different points in the rendering cycle. Any given
// prop may implement one or more of these methods. The first two
// methods are designed to render 3D geometry such as polygons
// lines, triangles. We render the opaque first then the transparent.
// The next two methods are primarily intended for volume rendering
// and support ray casting and any other technique that returns an
// image to be composited. The fifth method is to render any 2D
// annotation or overlays.
virtual void RenderOpaqueGeometry(vtkViewport *viewport) {};
virtual void RenderTranslucentGeometry(vtkViewport *viewport) {};
virtual void RenderRayCastImage(vtkViewport *viewport) {};
virtual void RenderAndReturnImage(vtkViewport *viewport) {};
virtual void RenderOverlay(vtkViewport *viewport) {};
// Description:
// For some exporters and other other operations we must be
// able to collect all the actors or volumes. These methods
// are used in that process.
virtual void GetActors(vtkActorCollection *ac) {};
virtual void GetActors2D(vtkActor2DCollection *ac) {};
virtual void GetVolumes(vtkVolumeCollection *vc) {};
// Description:
// Set/Get visibility of this vtkProp.
vtkSetMacro(Visibility, int);
vtkGetMacro(Visibility, int);
vtkBooleanMacro(Visibility, int);
// Description:
// The renderer may use the allocated rendering time to determine
// how to render this actor. (LOD Experiment)
// The set method is not a macro in order to avoid resetting the mtime of
// the actor - otherwise the actor would have been modified during every
// render.
void SetAllocatedRenderTime(float t) {this->AllocatedRenderTime = t;};
vtkGetMacro(AllocatedRenderTime, float);
// Description:
// Return the mtime of anything that would cause the rendered image to
// appear differently. Usually this involves checking the mtime of the
// prop plus anything else it depends on such as properties, textures
// etc.
virtual unsigned long GetRedrawMTime() {return this->GetMTime();};
// Description:
// Get the bounds for this Prop as (Xmin,Xmax,Ymin,Ymax,Zmin,Zmax).
// in world coordinates. NULL means that the bounds are not defined.
virtual float *GetBounds() {return NULL;};
protected:
int Visibility;
float AllocatedRenderTime;
};
#endif
/*=========================================================================
Program: Visualization Toolkit
Module: vtkProp2D.h
Module: vtkPropCollection.h
Language: C++
Date: $Date$
Version: $Revision$
Thanks: Thanks to Matt Turek who developed this class.
Copyright (c) 1993-1998 Ken Martin, Will Schroeder, Bill Lorensen.
......@@ -38,86 +38,84 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
=========================================================================*/
// .NAME vtkProp2D - abstract superclass for 2D actors
// .NAME vtkPropCollection - a list of Props
// .SECTION Description
// vtkProp2D is an abstract superclass for 2D actors. Instances of
// vtkProp draw into the image or overlay plane in a viewport. You can
// control whether the the 2D actor is visible, which overlay plane to
// draw into (vtkProp2D has a layer property which allows two
// dimensional actors to be rendered on top of each other in a certain
// order), and control its position on the screen.
//
// .SECTION See Also
// vtkActor2D vtkMapper2D
#ifndef __vtkProp2D_h
#define __vtkProp2D_h
#include "vtkObject.h"
#include "vtkCoordinate.h"
#include "vtkProperty2D.h"
class VTK_EXPORT vtkProp2D : public vtkObject
// vtkPropCollection represents and provides methods to manipulate a list of
// Props (i.e., vtkProp and subclasses). The list is unsorted and duplicate
// entries are not prevented.
// .SECTION see also
// vtkProp vtkCollection
#ifndef __vtkPropC_h
#define __vtkPropC_h
#include "vtkCollection.h"
class vtkProp;
class VTK_EXPORT vtkPropCollection : public vtkCollection
{
public:
// Description:
// Creates an Prop2D with the following defaults:
// position -1, -1 (view coordinates), layer 0, and visibility on.
vtkProp2D();
public:
static vtkPropCollection *New() {return new vtkPropCollection;};
const char *GetClassName() {return "vtkPropCollection";};
// Description:
// Destroy an Prop2D. If the Prop2D created it's own
// property, that property is deleted.
~vtkProp2D();
// Add an Prop to the list.
void AddItem(vtkProp *a);
void PrintSelf(ostream& os, vtkIndent indent);