Commit 78e59e86 authored by Mathieu Westphal's avatar Mathieu Westphal
Browse files

Adding Center Cursor

In order to have a better visualization of the center
of the sphere widget, this commit had a vtkCursor at the center of the widget
which can be shown or not.
parent 2b541343
......@@ -58,6 +58,7 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
TestSliderWidget.cxx
TestSplineWidget.cxx
TestSphereWidgetZoomInOut.cxx
TestSphereWidget2CenterCursor.cxx
TestTextWidget.cxx
)
vtk_add_test_cxx(${vtk-module}CxxTests no_valid_tests
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestSphereWidgetCenterCursor.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include <vtkCamera.h>
#include <vtkCommand.h>
#include <vtkMath.h>
#include <vtkNew.h>
#include <vtkRegressionTestImage.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkSphere.h>
#include <vtkSphereRepresentation.h>
#include <vtkSphereWidget2.h>
int TestSphereWidget2CenterCursor( int argc, char* argv[] )
{
// Create a renderer and a render window
vtkNew<vtkRenderer> renderer;
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->AddRenderer(renderer.Get());
// Create an interactor
vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
renderWindowInteractor->SetRenderWindow(renderWindow.Get());
// Create a sphere widget
vtkNew<vtkSphereWidget2> sphereWidget;
sphereWidget->SetInteractor(renderWindowInteractor.Get());
sphereWidget->CreateDefaultRepresentation();
vtkSphereRepresentation* sphereRepresentation =
vtkSphereRepresentation::SafeDownCast( sphereWidget->GetRepresentation() );
sphereRepresentation->HandleVisibilityOff();
double center[3] = {4, 0, 0};
sphereRepresentation->SetCenter(center);
sphereRepresentation->SetRadius(3);
// Create a second sphere widget
vtkNew<vtkSphereWidget2> sphereWidget2;
sphereWidget2->SetInteractor(renderWindowInteractor.Get());
sphereWidget2->CreateDefaultRepresentation();
vtkSphereRepresentation* sphereRepresentation2 =
vtkSphereRepresentation::SafeDownCast( sphereWidget2->GetRepresentation() );
sphereRepresentation2->HandleVisibilityOff();
double center2[3] = {-4, 0, 0};
sphereRepresentation2->SetCenter(center2);
sphereRepresentation2->SetRadius(3);
sphereRepresentation2->SetCenterCursor(true);
vtkCamera* camera = renderer->GetActiveCamera();
renderWindow->SetSize(300, 300);
camera->SetPosition(0.0, 0.0, 20.0);
camera->SetFocalPoint(0.0, 0.0, -1);
renderWindow->Render();
renderWindowInteractor->Initialize();
sphereWidget->On();
sphereWidget2->On();
renderWindow->Render();
int retVal = vtkRegressionTestImage( renderWindow.Get() );
if ( retVal == vtkRegressionTester::DO_INTERACTOR)
{
renderWindowInteractor->Start();
}
return !retVal;
}
......@@ -12,35 +12,33 @@
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkSphereRepresentation.h"
#include "vtkActor.h"
#include "vtkSphere.h"
#include "vtkSphereSource.h"
#include "vtkPickingManager.h"
#include "vtkPolyDataMapper.h"
#include "vtkPolyData.h"
#include "vtkActor2D.h"
#include "vtkAssemblyPath.h"
#include "vtkCallbackCommand.h"
#include "vtkCamera.h"
#include "vtkCellArray.h"
#include "vtkCellPicker.h"
#include "vtkCursor3D.h"
#include "vtkDoubleArray.h"
#include "vtkInteractorObserver.h"
#include "vtkLineSource.h"
#include "vtkMath.h"
#include "vtkObjectFactory.h"
#include "vtkPickingManager.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkInteractorObserver.h"
#include "vtkMath.h"
#include "vtkCellArray.h"
#include "vtkCellPicker.h"
#include "vtkTransform.h"
#include "vtkDoubleArray.h"
#include "vtkSphere.h"
#include "vtkCamera.h"
#include "vtkAssemblyPath.h"
#include "vtkSphereRepresentation.h"
#include "vtkSphereSource.h"
#include "vtkTextMapper.h"
#include "vtkActor2D.h"
#include "vtkTextProperty.h"
#include "vtkLineSource.h"
#include "vtkTransform.h"
#include "vtkWindow.h"
#include "vtkObjectFactory.h"
vtkStandardNewMacro(vtkSphereRepresentation);
......@@ -110,6 +108,18 @@ vtkSphereRepresentation::vtkSphereRepresentation()
this->RadialLineActor->SetMapper(this->RadialLineMapper);
this->RadialLineActor->SetProperty(this->RadialLineProperty);
// Represent the center cursor
this->CenterCursor = 0;
this->CenterCursorSource = vtkCursor3D::New();
this->CenterCursorSource->AllOff();
this->CenterCursorSource->AxesOn();
this->CenterCursorSource->TranslationModeOn();
this->CenterMapper = vtkPolyDataMapper::New();
this->CenterMapper->SetInputConnection(
this->CenterCursorSource->GetOutputPort());
this->CenterActor = vtkActor::New();
this->CenterActor->SetMapper(this->CenterMapper);
// Define the point coordinates
double bounds[6];
bounds[0] = -0.5;
......@@ -162,6 +172,11 @@ vtkSphereRepresentation::~vtkSphereRepresentation()
this->RadialLineMapper->Delete();
this->RadialLineActor->Delete();
// The cursor
this->CenterCursorSource->Delete();
this->CenterMapper->Delete();
this->CenterActor->Delete();
if ( this->SphereProperty )
{
this->SphereProperty->Delete();
......@@ -362,6 +377,7 @@ void vtkSphereRepresentation::Translate(double *p1, double *p2)
}
this->SphereSource->SetCenter(center1);
this->CenterCursorSource->SetFocalPoint(center1);
this->HandleSource->SetCenter(HandlePosition);
}
......@@ -419,6 +435,9 @@ void vtkSphereRepresentation::PlaceWidget(double center[3], double handle[3])
this->HandleSource->SetCenter(handle);
this->HandleSource->Update();
this->CenterCursorSource->SetFocalPoint(center);
this->CenterCursorSource->Update();
this->HandleDirection[0] = handle[0] - center[0];
this->HandleDirection[1] = handle[1] - center[1];
this->HandleDirection[2] = handle[2] - center[2];
......@@ -457,6 +476,10 @@ void vtkSphereRepresentation::SetCenter(double center[3])
}
this->SphereSource->Update();
this->CenterCursorSource->SetFocalPoint(center);
this->CenterCursorSource->Update();
this->Modified();
}
}
......@@ -545,6 +568,9 @@ void vtkSphereRepresentation::PlaceWidget(double bds[6])
this->SphereSource->SetRadius(radius);
this->SphereSource->Update();
this->CenterCursorSource->SetFocalPoint(center);
this->CenterCursorSource->Update();
// place the handle
this->PlaceHandle(center,radius);
......@@ -686,6 +712,7 @@ void vtkSphereRepresentation::ReleaseGraphicsResources(vtkWindow *w)
this->HandleActor->ReleaseGraphicsResources(w);
this->HandleTextActor->ReleaseGraphicsResources(w);
this->RadialLineActor->ReleaseGraphicsResources(w);
this->CenterActor->ReleaseGraphicsResources(w);
}
//----------------------------------------------------------------------------
......@@ -706,6 +733,10 @@ int vtkSphereRepresentation::RenderOpaqueGeometry(vtkViewport *v)
{
count += this->RadialLineActor->RenderOpaqueGeometry(v);
}
if (this->CenterCursor)
{
count += this->CenterActor->RenderOpaqueGeometry(v);
}
return count;
}
......@@ -727,6 +758,10 @@ int vtkSphereRepresentation::RenderTranslucentPolygonalGeometry(vtkViewport *v)
{
count += this->RadialLineActor->RenderTranslucentPolygonalGeometry(v);
}
if (this->CenterCursor)
{
count += this->CenterActor->RenderTranslucentPolygonalGeometry(v);
}
return count;
}
......@@ -766,6 +801,10 @@ int vtkSphereRepresentation::HasTranslucentPolygonalGeometry()
{
result |= this->RadialLineActor->HasTranslucentPolygonalGeometry();
}
if (this->CenterCursor)
{
result |= this->CenterActor->HasTranslucentPolygonalGeometry();
}
return result;
}
......@@ -858,6 +897,7 @@ void vtkSphereRepresentation::PrintSelf(ostream& os, vtkIndent indent)
os << indent << "Handle Text: " << this->HandleText << "\n";
os << indent << "Radial Line: " << this->RadialLine << "\n";
os << indent << "Center Cursor: " << this->CenterCursor << "\n";
if ( this->HandleTextProperty )
{
......
......@@ -63,6 +63,7 @@ class vtkTextMapper;
class vtkActor2D;
class vtkTextProperty;
class vtkLineSource;
class vtkCursor3D;
#define VTK_SPHERE_OFF 0
#define VTK_SPHERE_WIREFRAME 1
......@@ -171,6 +172,13 @@ public:
vtkGetMacro(RadialLine,int);
vtkBooleanMacro(RadialLine,int);
// Description:
// Enable/disable a center cursor
// Default is disabled
vtkSetMacro(CenterCursor, bool);
vtkGetMacro(CenterCursor, bool);
vtkBooleanMacro(CenterCursor, bool);
// Description:
// Grab the polydata (including points) that defines the sphere. The
// polydata consists of n+1 points, where n is the resolution of the
......@@ -299,6 +307,12 @@ protected:
vtkPolyDataMapper *RadialLineMapper;
vtkActor *RadialLineActor;
// Managing the center cursor
vtkActor *CenterActor;
vtkPolyDataMapper *CenterMapper;
vtkCursor3D *CenterCursorSource;
bool CenterCursor;
private:
vtkSphereRepresentation(const vtkSphereRepresentation&); //Not implemented
void operator=(const vtkSphereRepresentation&); //Not implemented
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment