Commit 1570c61d authored by Philippe Pebay's avatar Philippe Pebay Committed by Kitware Robot
Browse files

Merge topic 'Add2DFeaturesTo3DCubeAxes'

3ac3f09b Using adjustable X and Y 2 offsets (defaults: -40 and -50)
a49b0e9a Created instance variables to control fixed title offsets in 2D mode
62d41108 Restored utilization of NeedBuild2D ivar for speed
e42d9ced Restored building of 2D titles
e97dc120 Program generically (globally-defined constant instead of "4")
a6fd8d1f Better coding style; format; documentation; for 2D mode
0a38bb62 Use 2D mode for test
38c54bc7 Emliminated flickering between edgges and surface
2d44b2c9 Testing many more features now
903358a9 Fixed 2D test code so that it can actually compile
011645da Documentation and coding style; reformatting
62f12f77 Build the 2DMode test for 3D cube axes
38648ef3 A test for the 2DMode features of the 3D cube axes actor
parents efd33d78 3ac3f09b
......@@ -55,7 +55,9 @@ polaxes.GetPolarArcsProperty().SetColor( 1., .0, 0. )
polaxes.GetPolarAxisProperty().SetColor( 0., 1., 0. )
polaxes.GetPolarAxisTitleTextProperty().SetColor( 0., 1., 0. )
polaxes.GetPolarAxisLabelTextProperty().SetColor( 0., 1., 0. )
polaxes.SetEnableDistanceLOD( 0 )
polaxes.SetDistanceLODThreshold( .4 )
polaxes.SetEnableViewAngleLOD( 0 )
polaxes.SetViewAngleLODThreshold( .2 )
polaxes.SetScreenSize( 8. )
......@@ -72,4 +74,8 @@ interactor.SetRenderWindow( window )
# Start interaction
window.Render()
polaxes.SetMaximumAngle( 120. )
window.Render()
interactor.Start()
......@@ -8,6 +8,7 @@ IF (VTK_DATA_ROOT)
# add tests that require data
SET(MyTests ${MyTests}
# TestAxisActor3D.cxx
TestCubeAxes2DMode.cxx
TestCubeAxes3.cxx
TestCubeAxesWithGridLines.cxx
TestCubeAxesWithXLines.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestCubeAxesWithGridlines.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.
=========================================================================*/
// .SECTION Thanks
// This test was written by Philippe Pebay, Kitware SAS 2011
#include "vtkActor.h"
#include "vtkAxisActor.h"
#include "vtkCamera.h"
#include "vtkCoordinate.h"
#include "vtkCubeAxesActor.h"
#include "vtkPlaneSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkProperty2D.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSmartPointer.h"
#include "vtkStructuredGrid.h"
#include "vtkTextProperty.h"
#include "vtkCubeAxesActor.h"
int TestCubeAxes2DMode( int argc, char * argv [] )
{
// Create plane source
vtkSmartPointer<vtkPlaneSource> plane
= vtkSmartPointer<vtkPlaneSource>::New();
plane->SetXResolution( 10 );
plane->SetYResolution( 10 );
// Create plane mapper
vtkSmartPointer<vtkPolyDataMapper> planeMapper
= vtkSmartPointer<vtkPolyDataMapper>::New();
planeMapper->SetInputConnection( plane->GetOutputPort() );
planeMapper->SetResolveCoincidentTopologyPolygonOffsetParameters( 0, 1 );
planeMapper->SetResolveCoincidentTopologyToPolygonOffset();
// Create plane actor
vtkSmartPointer<vtkActor> planeActor
= vtkSmartPointer<vtkActor>::New();
planeActor->SetMapper( planeMapper );
planeActor->GetProperty()->SetColor( .5, .5, .5 );
// Create edge mapper and actor
vtkSmartPointer<vtkPolyDataMapper> edgeMapper
= vtkSmartPointer<vtkPolyDataMapper>::New();
edgeMapper->SetInputConnection( plane->GetOutputPort() );
edgeMapper->SetResolveCoincidentTopologyPolygonOffsetParameters( 1, 1 );
edgeMapper->SetResolveCoincidentTopologyToPolygonOffset();
// Create edge actor
vtkSmartPointer<vtkActor> edgeActor
= vtkSmartPointer<vtkActor>::New();
edgeActor->SetMapper( edgeMapper );
edgeActor->GetProperty()->SetColor( .0, .0, .0 );
edgeActor->GetProperty()->SetRepresentationToWireframe();
// Create renderer
vtkSmartPointer<vtkRenderer> renderer
= vtkSmartPointer<vtkRenderer>::New();
renderer->SetBackground( 1., 1., 1. );
renderer->GetActiveCamera()->SetFocalPoint( .0, .0, .0 );
renderer->GetActiveCamera()->SetPosition( .0, .0, 2.5 );
// Create cube axes actor
vtkSmartPointer<vtkCubeAxesActor> axes = vtkSmartPointer<vtkCubeAxesActor>::New();
axes->SetCamera ( renderer->GetActiveCamera() );
axes->SetBounds( -.5, .5, -.5, .5, 0., 0. );
axes->SetCornerOffset( .0 );
axes->SetXAxisVisibility( 1 );
axes->SetYAxisVisibility( 1 );
axes->SetZAxisVisibility( 0 );
axes->SetUse2DMode( 1 );
// Desactivate LOD for all axes
axes->SetEnableDistanceLOD( 0 );
axes->SetEnableViewAngleLOD( 0 );
// Use red color for X axis
axes->GetXAxesLinesProperty()->SetColor( 1., 0., 0.);
axes->GetTitleTextProperty( 0 )->SetColor( 1., 0., 0.);
axes->GetLabelTextProperty( 0 )->SetColor( 1., 0., 0.);
// Use green color for Y axis
axes->GetYAxesLinesProperty()->SetColor( 0., 1., 0. );
axes->GetTitleTextProperty( 1 )->SetColor( 0., 1., 0. );
axes->GetLabelTextProperty( 1 )->SetColor( 0., 1., 0. );
// Add all actors to renderer
renderer->AddActor( planeActor );
renderer->AddActor( edgeActor );
renderer->AddActor( axes );
// Create render window and interactor
vtkSmartPointer<vtkRenderWindow> renderWindow
= vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer( renderer );
renderWindow->SetSize( 800, 600 );
vtkSmartPointer<vtkRenderWindowInteractor> interactor
= vtkSmartPointer<vtkRenderWindowInteractor>::New();
interactor->SetRenderWindow( renderWindow );
// Render and possibly interact
renderWindow->Render();
int retVal = vtkRegressionTestImage( renderWindow );
if ( retVal == vtkRegressionTester::DO_INTERACTOR)
{
interactor->Start();
}
return !retVal;
}
......@@ -13,13 +13,6 @@
=========================================================================*/
// This example illustrates how one may explicitly specify the range of each
// axes that's used to define the prop, while displaying data with a different
// set of bounds (unlike cubeAxes2.tcl). This example allows you to separate
// the notion of extent of the axes in physical space (bounds) and the extent
// of the values it represents. In other words, you can have the ticks and
// labels show a different range.
#include "vtkBYUReader.h"
#include "vtkCamera.h"
#include "vtkCubeAxesActor.h"
......@@ -94,29 +87,29 @@ int TestCubeAxes3( int argc, char * argv [] )
normals->Update();
vtkNew<vtkCubeAxesActor> axes2;
axes2->SetBounds(normals->GetOutput()->GetBounds());
axes2->SetXAxisRange(20, 300);
axes2->SetYAxisRange(-0.01, 0.01);
axes2->SetCamera(ren2->GetActiveCamera());
axes2->SetXLabelFormat("%6.1f");
axes2->SetYLabelFormat("%6.1f");
axes2->SetZLabelFormat("%6.1f");
axes2->SetScreenSize(15.0);
axes2->SetFlyModeToClosestTriad();
axes2->SetCornerOffset(0.0);
vtkNew<vtkCubeAxesActor> axes;
axes->SetBounds( normals->GetOutput()->GetBounds() );
axes->SetXAxisRange( 20, 300 );
axes->SetYAxisRange( -.01, .01 );
axes->SetCamera(ren2->GetActiveCamera());
axes->SetXLabelFormat( "%6.1f" );
axes->SetYLabelFormat( "%6.1f" );
axes->SetZLabelFormat( "%6.1f" );
axes->SetScreenSize( 15. );
axes->SetFlyModeToClosestTriad();
axes->SetCornerOffset( .0 );
// Use red color for X axis
axes2->GetXAxesLinesProperty()->SetColor(1., 0., 0.);
axes2->GetTitleTextProperty(0)->SetColor(1., 0., 0.);
axes2->GetLabelTextProperty(0)->SetColor(.8, 0., 0.);
axes->GetXAxesLinesProperty()->SetColor( 1., 0., 0. );
axes->GetTitleTextProperty(0)->SetColor( 1., 0., 0. );
axes->GetLabelTextProperty(0)->SetColor( .8, 0., 0. );
// Use green color for Y axis
axes2->GetYAxesLinesProperty()->SetColor(0., 1., 0.);
axes2->GetTitleTextProperty(1)->SetColor(0., 1., 0.);
axes2->GetLabelTextProperty(1)->SetColor(0., .8, 0.);
axes->GetYAxesLinesProperty()->SetColor( 0., 1., 0. );
axes->GetTitleTextProperty(1)->SetColor( 0., 1., 0. );
axes->GetLabelTextProperty(1)->SetColor( 0., .8, 0. );
ren2->AddViewProp(axes2.GetPointer());
ren2->AddViewProp( axes.GetPointer()) ;
renWin->Render();
int retVal = vtkRegressionTestImage( renWin.GetPointer() );
......
......@@ -65,10 +65,6 @@ vtkAxisActor::vtkAxisActor()
this->LabelFormat = new char[8];
sprintf(this->LabelFormat, "%s", "%-#6.3g");
this->Use2DMode = 0;
this->SaveTitlePosition = 0;
this->TitleConstantPosition[0] = this->TitleConstantPosition[1] = 0.0;
this->TitleTextProperty = vtkTextProperty::New();
this->TitleTextProperty->SetColor(0.,0.,0.);
this->TitleTextProperty->SetFontFamilyToArial();
......@@ -180,6 +176,13 @@ vtkAxisActor::vtkAxisActor()
{
vtkErrorMacro(<<"Failed getting the FreeType utilities instance");
}
// Instance variables specific to 2D mode
this->Use2DMode = 0;
this->SaveTitlePosition = 0;
this->TitleConstantPosition[0] = this->TitleConstantPosition[1] = 0.;
this->VerticalOffsetXTitle2D = -40.;
this->HorizontalOffsetYTitle2D = -50.;
}
// ****************************************************************
......@@ -580,6 +583,10 @@ void vtkAxisActor::BuildAxis(vtkViewport *viewport, bool force)
if (this->Title != NULL && this->Title[0] != 0)
{
this->BuildTitle(force);
if( this->Use2DMode == 1 )
{
this->BuildTitle2D(viewport, force);
}
}
this->LastAxisPosition = this->AxisPosition;
......@@ -807,6 +814,7 @@ vtkAxisActor::SetLabelPositions2D(vtkViewport *viewport, bool force)
// **********************************************************************
void vtkAxisActor::BuildTitle(bool force)
{
this->NeedBuild2D = false;
if (!force && !this->TitleVisibility)
{
return;
......@@ -828,6 +836,7 @@ void vtkAxisActor::BuildTitle(bool force)
return;
}
this->NeedBuild2D = true;
switch (this->AxisType)
{
case VTK_AXIS_TYPE_X :
......@@ -931,11 +940,11 @@ vtkAxisActor::BuildTitle2D(vtkViewport *viewport, bool force)
viewport->GetDisplayPoint(transpos);
if (this->AxisType == VTK_AXIS_TYPE_X)
{
transpos[1] -= 12;
transpos[1] += this->VerticalOffsetXTitle2D;
}
else if (this->AxisType == VTK_AXIS_TYPE_Y)
{
transpos[0] -= 20;
transpos[0] += this->HorizontalOffsetYTitle2D;
}
if (transpos[1] < 10.) transpos[1] = 10.;
if (transpos[0] < 10.) transpos[0] = 10.;
......@@ -1102,10 +1111,11 @@ void vtkAxisActor::PrintSelf(ostream& os, vtkIndent indent)
os << indent << "LabelTextProperty: " << this->LabelTextProperty << endl;
os << indent << "TitleTextProperty: " << this->TitleTextProperty << endl;
os << indent << "SaveTitlePosition: " << this->SaveTitlePosition << endl;
os << indent << "Us2DMode: " << this->Use2DMode << endl;
}
os << indent << "SaveTitlePosition: " << this->SaveTitlePosition << endl;
os << indent << "VerticalOffsetXTitle2D" << this->VerticalOffsetXTitle2D << endl;
os << indent << "HorizontalOffsetYTitle2D" << this->HorizontalOffsetYTitle2D << endl;
}
// **************************************************************************
// Sets text string for label vectors. Allocates memory if necessary.
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkAxisActor.h
Language: C++
Date: $Date$
Version: $Revision$
Thanks: Kathleen Bonnell, B Division, Lawrence Livermore Nat'l Laboratory
Program: Visualization Toolkit
Module: vtkAxisActor.h
Language: C++
Date: $Date$
Version: $Revision$
Thanks: Kathleen Bonnell, B Division, Lawrence Livermore Nat'l Laboratory
Copyright (c) 1993-2000 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
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.
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.
=========================================================================*/
// .NAME vtkAxisActor - Create an axis with tick marks and labels
// .SECTION Description
......@@ -83,7 +83,7 @@ class vtkVectorText;
class VTK_HYBRID_EXPORT vtkAxisActor : public vtkActor
{
public:
public:
vtkTypeMacro(vtkAxisActor,vtkActor);
void PrintSelf(ostream& os, vtkIndent indent);
......@@ -95,7 +95,7 @@ public:
// Specify the position of the first point defining the axis.
virtual vtkCoordinate *GetPoint1Coordinate();
virtual void SetPoint1(double x[3])
{ this->SetPoint1(x[0], x[1], x[2]); }
{ this->SetPoint1(x[0], x[1], x[2]); }
virtual void SetPoint1(double x, double y, double z);
virtual double *GetPoint1();
......@@ -103,7 +103,7 @@ public:
// Specify the position of the second point defining the axis.
virtual vtkCoordinate *GetPoint2Coordinate();
virtual void SetPoint2(double x[3])
{ this->SetPoint2(x[0], x[1], x[2]); }
{ this->SetPoint2(x[0], x[1], x[2]); }
virtual void SetPoint2(double x, double y, double z);
virtual double *GetPoint2();
......@@ -153,11 +153,11 @@ public:
vtkGetMacro(TickLocation, int);
void SetTickLocationToInside(void)
{ this->SetTickLocation(VTK_TICKS_INSIDE); };
{ this->SetTickLocation(VTK_TICKS_INSIDE); };
void SetTickLocationToOutside(void)
{ this->SetTickLocation(VTK_TICKS_OUTSIDE); };
{ this->SetTickLocation(VTK_TICKS_OUTSIDE); };
void SetTickLocationToBoth(void)
{ this->SetTickLocation(VTK_TICKS_BOTH); };
{ this->SetTickLocation(VTK_TICKS_BOTH); };
// Description:
// Set/Get visibility of the axis line.
......@@ -259,13 +259,13 @@ public:
vtkGetMacro(AxisPosition, int);
void SetAxisPositionToMinMin(void)
{ this->SetAxisPosition(VTK_AXIS_POS_MINMIN); };
{ this->SetAxisPosition(VTK_AXIS_POS_MINMIN); };
void SetAxisPositionToMinMax(void)
{ this->SetAxisPosition(VTK_AXIS_POS_MINMAX); };
{ this->SetAxisPosition(VTK_AXIS_POS_MINMAX); };
void SetAxisPositionToMaxMax(void)
{ this->SetAxisPosition(VTK_AXIS_POS_MAXMAX); };
{ this->SetAxisPosition(VTK_AXIS_POS_MAXMAX); };
void SetAxisPositionToMaxMin(void)
{ this->SetAxisPosition(VTK_AXIS_POS_MAXMIN); };
{ this->SetAxisPosition(VTK_AXIS_POS_MAXMIN); };
// Description:
// Set/Get the camera for this axis. The camera is used by the
......@@ -349,29 +349,41 @@ public:
// this count does not change.
vtkGetMacro(NumberOfLabelsBuilt, int);
// Description
// Description:
// Set/Get flag whether to calculate title offset.
// Default is true.
vtkSetMacro(CalculateTitleOffset, int);
vtkGetMacro(CalculateTitleOffset, int);
vtkBooleanMacro(CalculateTitleOffset, int);
// Description
// Description:
// Set/Get flag whether to calculate label offset.
// Default is true.
vtkSetMacro(CalculateLabelOffset, int);
vtkGetMacro(CalculateLabelOffset, int);
vtkBooleanMacro(CalculateLabelOffset, int);
// Set/Get the 2D mode (2D/3D)
vtkSetMacro(Use2DMode, int);
vtkGetMacro(Use2DMode, int);
// Set/Get the saving positions tag (2D/3D)
vtkSetMacro(SaveTitlePosition, int);
vtkGetMacro(SaveTitlePosition, int);
// Description:
// Set/Get the 2D mode
vtkSetMacro(Use2DMode, int);
vtkGetMacro(Use2DMode, int);
protected:
// Description:
// Set/Get the 2D mode the vertical offset for X title in 2D mode
vtkSetMacro(VerticalOffsetXTitle2D, double);
vtkGetMacro(VerticalOffsetXTitle2D, double);
// Description:
// Set/Get the 2D mode the horizontal offset for Y title in 2D mode
vtkSetMacro(HorizontalOffsetYTitle2D, double);
vtkGetMacro(HorizontalOffsetYTitle2D, double);
// Description:
// Set/Get whether title position must be saved in 2D mode
vtkSetMacro(SaveTitlePosition, int);
vtkGetMacro(SaveTitlePosition, int);
protected:
vtkAxisActor();
~vtkAxisActor();
......@@ -406,7 +418,7 @@ protected:
int AxisPosition;
double Bounds[6];
private:
private:
vtkAxisActor(const vtkAxisActor&); // Not implemented
void operator=(const vtkAxisActor&); // Not implemented
......@@ -502,14 +514,24 @@ private:
int Use2DMode;
// Description:
// Save title position (for 2D mode):
// Vertical offset in display coordinates for X axis title (used in 2D mode only)
// Default: -40
double VerticalOffsetXTitle2D;
// Description:
// Vertical offset in display coordinates for X axis title (used in 2D mode only)
// Default: -50
double HorizontalOffsetYTitle2D;
// Description:
// Save title position (used in 2D mode only):
// val = 0 : no need to save position (doesn't stick actors in a position)
// val = 1 : positions have to be saved during the next render pass
// val = 2 : positions are saved -> used them
// val = 2 : positions are saved; use them
int SaveTitlePosition;
// Description:
// Constant position for the title (for 2D mode)
// Constant position for the title (used in 2D mode only)
double TitleConstantPosition[2];
// Description:
......
......@@ -281,43 +281,37 @@ vtkCubeAxesActor::vtkCubeAxesActor() : vtkActor()
this->TitleScale = -1.0;
}
//! use textactor (2D) instead of follower (3D) for title
void vtkCubeAxesActor::SetUse2DMode( int val )
{
for( int i=0 ; i < 4 ; ++i )
for( int i = 0 ; i < NUMBER_OF_ALIGNED_AXIS ; ++ i )
{
this->XAxes[i]->SetUse2DMode( val );
this->YAxes[i]->SetUse2DMode( val );
this->ZAxes[i]->SetUse2DMode( val );
}
if( val == 0 )
if( ! val )
{
this->SetZAxisVisibility(1);
this->SetZAxisVisibility( 1 );
}
else
{
this->SetZAxisVisibility(0);
this->SetZAxisVisibility( 0 );
}
}
//! return 1 if textactor is used
int vtkCubeAxesActor::GetUse2DMode()
{
// we assume that all axes have the same value ...
// It is assumed that all axes have the same value
return this->XAxes[0]->GetUse2DMode();
}
/*! for 2D axis only : during the next render, the axis positions have to be save for later use.
\param val : the new state
\note
\li val = 0 : no need to save position (3D axis)
\li val = 1 : positions have to be saved during the next render pass
\li val = 2 : positions are saved -> used them
*/
void vtkCubeAxesActor::SetSaveTitlePosition( int val )
{
for( int i=0 ; i < 4 ; ++i )
// For 2D mode only :
// val = 0: no need to save position (3D axis)
// val = 1: positions have to be saved during the next render pass
// val = 2: positions are saved -> use them
for( int i = 0 ; i < NUMBER_OF_ALIGNED_AXIS ; ++ i )
{
this->XAxes[i]->SetSaveTitlePosition( val );
this->YAxes[i]->SetSaveTitlePosition( val );
......
......@@ -366,11 +366,14 @@ public:
void SetLabelScaling(bool, int, int, int);
//! use textactor if val = 1 (2D) instead of follower (3D - val = 0) for title
// Description:
// Get/Set 2D mode
// NB: Use vtkTextActor for titles in 2D instead of vtkAxisFollower
void SetUse2DMode( int val );
//! return 1 if textactor is used
int GetUse2DMode();
//! for 2D axis only : during the next render, the axis positions have to be save for later use.
// Description:
// For 2D mode only: save axis title positions for later use
void SetSaveTitlePosition( int val );
protected:
......
Supports Markdown
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