Commit 7e94b1c8 authored by Dave Demarle's avatar Dave Demarle
Browse files

ENH: Add test for vtkVisibleCellSelection and vtkFrustumExtractor. BUG: 1)...

ENH: Add test for vtkVisibleCellSelection and vtkFrustumExtractor. BUG: 1) Allow actor selection to work without having to supply a prop addr to id map by creating one automatically. 2) Fix non selectable actor invisibility. 3) Obey the pickable flag.
parent 99b7546b
......@@ -14,6 +14,17 @@ IF(VTK_USE_DISPLAY)
LoadOpenGLExtension.cxx
TestOrderedTriangulator.cxx
)
IF(VTK_USE_PARALLEL AND VTK_USE_MPI)
# This odd condition is here because of antialiasing
# if antialising is on compositing won't work
# and neither will visible cell selection.
SET(RenderingTestsWithArguments
${RenderingTestsWithArguments}
TestAreaSelections.cxx
)
ENDIF(VTK_USE_PARALLEL AND VTK_USE_MPI)
ENDIF(VTK_USE_DISPLAY)
CREATE_TEST_SOURCELIST(Tests ${KIT}CxxTests.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestAreaSelections.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.
=========================================================================*/
// This tests vtkVisibleCellSelector, vtkFrustumExtractor,
// vtkRenderedAreaPicker, and vtkInteractorStyleRubberBandPick.
//
// The command line arguments are:
// -I => run in interactive mode; unless this is used, the program will
// not allow interaction and exit
#include "vtkTestUtilities.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSphereSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkInteractorStyleRubberBandPick.h"
#include "vtkCallbackCommand.h"
#include "vtkVisibleCellSelector.h"
#include "vtkSelection.h"
#include "vtkPolyDataExtractSelection.h"
#include "vtkIdTypeArray.h"
#include "vtkRenderedAreaPicker.h"
#include "vtkCamera.h"
#include "vtkImageMandelbrotSource.h"
#include "vtkImageActor.h"
#include "vtkFrustumExtractor.h"
#include "vtkDataSetMapper.h"
#include "vtkDataSetReader.h"
vtkRenderer *renderer = NULL;
vtkSphereSource* SS1 = NULL;
vtkDataSetMapper* sMap = NULL;
vtkPolyData* emptyPD = NULL;
static void EndPick(vtkObject *vtkNotUsed( caller ),
unsigned long vtkNotUsed(eventId),
void *, void *)
{
vtkVisibleCellSelector *sel = vtkVisibleCellSelector::New();
sel->SetRenderer(renderer);
double x0 = renderer->GetPickX1();
double y0 = renderer->GetPickY1();
double x1 = renderer->GetPickX2();
double y1 = renderer->GetPickY2();
sel->SetRenderPasses(0,1,0,1,1);
sel->SetArea((int)x0,(int)y0,(int)x1,(int)y1);
sel->Select();
vtkSelection *res = vtkSelection::New();
sel->GetSelectedIds(res);
/*
cerr << "x0 " << x0 << " y0 " << y0 << "\t";
cerr << "x1 " << x1 << " y1 " << y1 << endl;
vtkIdTypeArray *a = vtkIdTypeArray::New();
sel->GetSelectedIds(a);
cerr << "numhits = " << a->GetNumberOfTuples() << endl;
sel->PrintSelectedIds(a);
a->Delete();
*/
vtkSelection *cellids = res->GetChild(0);
vtkPolyDataExtractSelection *extr = vtkPolyDataExtractSelection::New();
if (cellids)
{
extr->SetInput(SS1->GetOutput());
extr->SetSelection(cellids);
extr->Update();
sMap->SetInput(extr->GetOutput());
}
else
{
sMap->SetInput(emptyPD);
}
sel->Delete();
res->Delete();
extr->Delete();
}
int TestAreaSelections(int argc, char* argv[])
{
// Standard rendering classes
renderer = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(renderer);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
//set up the view
renderer->GetActiveCamera()->SetPosition( 1.5, -0.75, 7);
renderer->GetActiveCamera()->SetFocalPoint(1.5, -0.75, 0);
renderer->GetActiveCamera()->SetViewUp( 0, 1, 0);
renderer->SetBackground(0.0,0.0,0.0);
renWin->SetSize(300,300);
//use the rubber band pick interactor style
vtkRenderWindowInteractor* rwi = renWin->GetInteractor();
vtkInteractorStyleRubberBandPick *rbp =
vtkInteractorStyleRubberBandPick::New();
rwi->SetInteractorStyle(rbp);
vtkRenderedAreaPicker *areaPicker = vtkRenderedAreaPicker::New();
rwi->SetPicker(areaPicker);
////////////////////////////////////////////////////////////
//Create a unstructured grid data source to test FrustumExtractor with.
vtkDataSetReader *reader = vtkDataSetReader::New();
char *cfname=vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/SampleStructGrid.vtk");
reader->SetFileName(cfname);
reader->SetFileName("/home/demarle/Kitware/vtk/devel/VTKData/Data/SampleStructGrid.vtk");
vtkDataSetMapper *map1 = vtkDataSetMapper::New();
map1->SetInput(reader->GetOutput());
vtkActor *act1 = vtkActor::New();
act1->SetMapper(map1);
act1->PickableOff(); //prevents the visible cell selector from trying
renderer->AddActor(act1);
//frustum extractor works on geometry and doesn't care about pickability
vtkFrustumExtractor *extractor = vtkFrustumExtractor::New();
extractor->SetInputConnection(reader->GetOutputPort());
extractor->PassThroughOff();
extractor->ExactTestOn();
extractor->SetFrustum(areaPicker->GetFrustum());
vtkDataSetMapper *eMap = vtkDataSetMapper::New();
eMap->SetInput(extractor->GetOutput());
vtkActor *eAct = vtkActor::New();
eAct->SetPosition(2,0,0);
eAct->SetMapper(eMap);
eAct->PickableOff();
renderer->AddActor(eAct);
////////////////////////////////////////////////////////////
emptyPD = vtkPolyData::New();
int res = 20;
SS1 = vtkSphereSource::New();
SS1->SetThetaResolution(res);
SS1->SetPhiResolution(res);
SS1->SetRadius(0.5);
SS1->SetCenter(0.5,-1.5,0);
vtkPolyDataMapper *map2 = vtkPolyDataMapper::New();
map2->SetInput(SS1->GetOutput());
vtkActor* act2 = vtkActor::New();
act2->SetMapper(map2);
act2->PickableOn(); //lets the VisibleCellSelector select in it
renderer->AddActor(act2);
sMap = vtkDataSetMapper::New();
sMap->SetInput(SS1->GetOutput());
vtkActor *sAct = vtkActor::New();
sAct->SetMapper(sMap);
sAct->SetPosition(2,0,0);
sAct->PickableOff();
renderer->AddActor(sAct);
//pass pick events to the VisibleCellSelector
vtkCallbackCommand *cbc = vtkCallbackCommand::New();
cbc->SetCallback(EndPick);
cbc->SetClientData((void *)renderer);
rwi->AddObserver(vtkCommand::EndPickEvent,cbc);
cbc->Delete();
////////////////////////////////////////////////////////////
//run the test
areaPicker->AreaPick(51,78,82,273,renderer);
EndPick(NULL, 0, NULL, NULL);
renWin->Render();
int retVal = vtkRegressionTestImage( renWin );
if ( retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
// Cleanup
renderer->Delete();
renWin->Delete();
iren->Delete();
rbp->Delete();
areaPicker->Delete();
reader->Delete();
map1->Delete();
act1->Delete();
extractor->Delete();
eMap->Delete();
eAct->Delete();
emptyPD->Delete();
SS1->Delete();
map2->Delete();
act2->Delete();
sMap->Delete();
sAct->Delete();
return !retVal;
}
......@@ -37,7 +37,7 @@
#endif
//-----------------------------------------------------------------------------
vtkCxxRevisionMacro(vtkIdentColoredPainter, "1.6");
vtkCxxRevisionMacro(vtkIdentColoredPainter, "1.7");
vtkStandardNewMacro(vtkIdentColoredPainter);
//-----------------------------------------------------------------------------
......@@ -101,7 +101,7 @@ void vtkIdentColoredPainter::SetActorLookupTable(vtkProp **props, vtkIdTypeArray
(ids->GetNumberOfComponents() != 1) ||
(ids->GetNumberOfTuples() == 0))
{
vtkErrorMacro("Invalid actor lookup table");
vtkWarningMacro("Invalid actor-id lookup table supplied.");
return;
}
......@@ -116,24 +116,52 @@ void vtkIdentColoredPainter::SetActorLookupTable(vtkProp **props, vtkIdTypeArray
}
//-----------------------------------------------------------------------------
void vtkIdentColoredPainter::SetToColorByActorId(vtkProp *actorId)
void vtkIdentColoredPainter::SetToColorByActorId(vtkProp *actorAddr)
{
this->ColorMode = COLORBYCONST;
this->ResetCurrentId();
vtkIdType maxId = 0;
int numIds = 0;
if (this->ActorIds != NULL)
{
for (int i = 0; i< this->ActorIds->GetNumberOfTuples(); i++)
numIds = this->ActorIds->GetNumberOfTuples();
for (int i = 0; i< numIds; i++)
{
if (actorId == this->PropAddrs[i])
vtkIdType nextId = this->ActorIds->GetValue(i);
if (actorAddr == this->PropAddrs[i])
{
this->CurrentIdPlane0 = this->ActorIds->GetValue(i) + 1;
//cerr << "Saved Id for actor " << actorId << " is " << this->ActorIds->GetValue(i) << endl;
this->CurrentIdPlane0 = nextId + 1;
return;
}
if (nextId > maxId)
{
maxId = nextId;
}
}
}
//we didn't find the actor in the table, make up an ID and add it
//cerr << "ID not found for actor " << actorAddr
// << " using " << maxId+1 << endl;
vtkIdTypeArray *arr = vtkIdTypeArray::New();
arr->SetNumberOfComponents(1);
arr->SetNumberOfTuples(numIds+1);
vtkProp **SaveProps = new vtkProp*[numIds+1];
if (this->ActorIds != NULL)
{
for (int i = 0; i< numIds; i++)
{
arr->SetValue(i, this->ActorIds->GetValue(i));
SaveProps[i] = this->PropAddrs[i];
}
}
vtkErrorMacro("No saved id for actor " << actorId);
this->CurrentIdPlane0 = 0;
arr->SetValue(numIds, maxId+1);
SaveProps[numIds] = actorAddr;
this->SetActorLookupTable(SaveProps, arr);
arr->Delete();
this->CurrentIdPlane0 = maxId+1;
}
//-----------------------------------------------------------------------------
......
......@@ -38,7 +38,7 @@
#include "vtkPainterPolyDataMapper.h"
#include "vtkPolyDataPainter.h"
vtkCxxRevisionMacro(vtkRenderer, "1.229");
vtkCxxRevisionMacro(vtkRenderer, "1.230");
vtkCxxSetObjectMacro(vtkRenderer, IdentPainter, vtkIdentColoredPainter);
......@@ -1665,7 +1665,6 @@ int vtkRenderer::UpdateGeometryForSelection()
for ( i = 0; i < this->PropArrayCount; i++ )
{
this->PropsSelectedFrom[i] = this->PropArray[i];
if (this->SelectMode == vtkRenderer::COLOR_BY_ACTOR)
{
this->IdentPainter->SetToColorByActorId(this->PropArray[i]);
......@@ -1683,8 +1682,11 @@ int vtkRenderer::UpdateGeometryForSelection()
orig_painter = this->SwapInSelectablePainter(this->PropArray[i], orig_visibility);
//render the prop
this->NumberOfPropsRendered +=
this->PropArray[i]->RenderOpaqueGeometry(this);
if (this->PropArray[i]->GetVisibility())
{
this->NumberOfPropsRendered +=
this->PropArray[i]->RenderOpaqueGeometry(this);
}
//restore the prop's original settings
this->SwapOutSelectablePainter(this->PropArray[i], orig_painter, orig_visibility);
......@@ -1706,7 +1708,12 @@ vtkPolyDataPainter* vtkRenderer::SwapInSelectablePainter(
//try to find a polydatapainter that we can swap out
vtkActor *actor = vtkActor::SafeDownCast(prop);
if (actor && !(actor->IsA("vtkFollower") || actor->IsA("vtkLODActor")))
if (actor &&
!
(actor->IsA("vtkFollower") ||
actor->IsA("vtkLODActor") ||
!actor->GetPickable())
)
{
orig_mapper =
vtkPainterPolyDataMapper::SafeDownCast(actor->GetMapper());
......@@ -1742,7 +1749,11 @@ void vtkRenderer::SwapOutSelectablePainter(
vtkPainterPolyDataMapper *orig_mapper = NULL;
//try to restore the swapped out painter
vtkActor *actor = vtkActor::SafeDownCast(prop);
if (actor && !(actor->IsA("vtkFollower") || actor->IsA("vtkLODActor")))
if (actor &&
!
(actor->IsA("vtkFollower") ||
actor->IsA("vtkLODActor") ||
!actor->GetPickable()))
{
orig_mapper =
vtkPainterPolyDataMapper::SafeDownCast(actor->GetMapper());
......
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