Commit 6327999e authored by Ken Martin's avatar Ken Martin Committed by Kitware Robot
Browse files

Merge topic 'glyph_mapper_cell_picking'

b4b91eb5

 make sure the opengl2 glyph3dmapper honors cell picking
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: John Tourtellott's avatarJohn Tourtellott <john.tourtellott@kitware.com>
Merge-request: !2755
parents 8e5e6f44 b4b91eb5
Pipeline #57157 failed with stage
in 0 seconds
......@@ -93,7 +93,6 @@ vtkGlyph3DMapper::vtkGlyph3DMapper()
this->NestedDisplayLists = true;
this->Masking = false;
this->SelectMode=1;
this->SelectionColorId=1;
}
......@@ -416,7 +415,6 @@ void vtkGlyph3DMapper::PrintSelf(ostream& os, vtkIndent indent)
<< (this->UseSourceTableTree ? "On" : "Off") << endl;
os << indent << "UseSelectionIds: "
<< (this->UseSelectionIds? "On" : "Off") << endl;
os << indent << "SelectMode: " << this->SelectMode << endl;
os << indent << "SelectionColorId: " << this->SelectionColorId << endl;
os << "Masking: " << (this->Masking? "On" : "Off") << endl;
os << "NestedDisplayLists: " << (this->NestedDisplayLists? "On" : "Off") << endl;
......
......@@ -394,13 +394,6 @@ public:
vtkGetMacro(SelectionColorId, unsigned int);
//@}
//@{
/**
* Called by vtkGlyphSelectionRenderMode.
*/
vtkSetMacro(SelectMode, int);
//@}
/**
* WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE
* DO NOT USE THIS METHOD OUTSIDE OF THE RENDERING PROCESS
......@@ -451,7 +444,6 @@ protected:
bool UseSourceTableTree; // Map DataObjectTree glyph source into table
unsigned int SelectionColorId;
int SelectMode;
private:
vtkGlyph3DMapper(const vtkGlyph3DMapper&) VTK_DELETE_FUNCTION;
......
......@@ -47,7 +47,6 @@ public:
/**
* Method initiates the mapping process. Generally sent by the actor
* as each frame is rendered.
* Its behavior depends on the value of SelectMode.
*/
void Render(vtkRenderer *ren, vtkActor *a) VTK_OVERRIDE;
......
......@@ -12,6 +12,7 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
TestEDLPass.cxx
TestFXAAFilter.cxx
TestGaussianBlurPass.cxx
TestGlyph3DMapperCellPicking.cxx
TestLightingMapLuminancePass.cxx
TestLightingMapNormalsPass.cxx
TestPointFillPass.cxx
......
/*=========================================================================
Program: Visualization Toolkit
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, vtkExtractSelectedFrustum,
// 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 "vtkActor.h"
#include "vtkInteractorStyleRubberBandPick.h"
#include "vtkCommand.h"
#include "vtkHardwareSelector.h"
#include "vtkSelection.h"
#include "vtkIdTypeArray.h"
#include "vtkRenderedAreaPicker.h"
#include "vtkCamera.h"
#include "vtkImageActor.h"
#include "vtkPointData.h"
#include "vtkPlaneSource.h"
#include "vtkElevationFilter.h"
#include "vtkBitArray.h"
#include "vtkGlyph3DMapper.h"
#include "vtkSelection.h"
#include "vtkSelectionNode.h"
#include <cassert>
static vtkRenderer *renderer = NULL;
class MyEndPickCommand : public vtkCommand
{
public:
MyEndPickCommand()
{
this->Renderer=0; // no reference counting
this->Mask=0; // no reference counting
this->DataSet=0;
}
~MyEndPickCommand() VTK_OVERRIDE
{
// empty
}
void Execute(vtkObject *vtkNotUsed(caller),
unsigned long vtkNotUsed(eventId),
void *vtkNotUsed(callData)) VTK_OVERRIDE
{
assert("pre: renderer_exists" && this->Renderer!=0);
vtkHardwareSelector *sel = vtkHardwareSelector::New();
sel->SetFieldAssociation(vtkDataObject::FIELD_ASSOCIATION_CELLS);
sel->SetRenderer(renderer);
double x0 = renderer->GetPickX1();
double y0 = renderer->GetPickY1();
double x1 = renderer->GetPickX2();
double y1 = renderer->GetPickY2();
sel->SetArea(static_cast<unsigned int>(x0),
static_cast<unsigned int>(y0),
static_cast<unsigned int>(x1),
static_cast<unsigned int>(y1));
vtkSelection *res = sel->Select();
#if 1
cerr << "x0 " << x0 << " y0 " << y0 << "\t";
cerr << "x1 " << x1 << " y1 " << y1 << endl;
res->Print(cout);
#endif
// Reset the mask to false.
vtkIdType numPoints = this->Mask->GetNumberOfTuples();
for (vtkIdType i=0; i < numPoints; i++)
{
this->Mask->SetValue(i,false);
}
vtkSelectionNode *glyphids = res->GetNode(0);
if (glyphids!=0)
{
vtkAbstractArray *abs=glyphids->GetSelectionList();
if(abs==0)
{
cout<<"abs is null"<<endl;
}
vtkIdTypeArray *ids=vtkArrayDownCast<vtkIdTypeArray>(abs);
if(ids==0)
{
cout<<"ids is null"<<endl;
}
else
{
// modify mask array with selection.
vtkIdType numSelPoints = ids->GetNumberOfTuples();
for (vtkIdType i =0; i < numSelPoints; i++)
{
vtkIdType value = ids->GetValue(i);
if (value >=0 && value < numPoints)
{
cout << "Turn On: " << value << endl;
this->Mask->SetValue(value,true);
}
else
{
cout << "Ignoring: " << value << endl;
}
}
}
}
this->DataSet->Modified();
sel->Delete();
res->Delete();
}
void SetRenderer(vtkRenderer *r)
{
this->Renderer=r;
}
vtkRenderer *GetRenderer() const
{
return this->Renderer;
}
void SetMask(vtkBitArray *m)
{
this->Mask=m;
}
void SetDataSet(vtkDataSet* ds)
{
this->DataSet = ds;
}
protected:
vtkRenderer *Renderer;
vtkBitArray *Mask;
vtkDataSet *DataSet;
};
int TestGlyph3DMapperCellPicking(int argc, char* argv[])
{
int res=1;
vtkPlaneSource *plane=vtkPlaneSource::New();
plane->SetResolution(res,res);
vtkElevationFilter *colors=vtkElevationFilter::New();
colors->SetInputConnection(plane->GetOutputPort());
plane->Delete();
colors->SetLowPoint(-1,-1,-1);
colors->SetHighPoint(0.5,0.5,0.5);
vtkSphereSource *squad=vtkSphereSource::New();
squad->SetPhiResolution(4);
squad->SetThetaResolution(6);
vtkGlyph3DMapper *glypher=vtkGlyph3DMapper::New();
// glypher->SetNestedDisplayLists(0);
glypher->SetInputConnection(colors->GetOutputPort());
colors->Delete();
glypher->SetScaleFactor(1.5);
glypher->SetSourceConnection(squad->GetOutputPort());
squad->Delete();
// selection is performed on actor1
vtkActor *glyphActor1=vtkActor::New();
glyphActor1->SetMapper(glypher);
glypher->Delete();
glyphActor1->PickableOn();
// result of selection is on actor2
vtkActor *glyphActor2=vtkActor::New();
glyphActor2->PickableOff();
colors->Update(); // make sure output is valid.
vtkDataSet *selection=colors->GetOutput()->NewInstance();
selection->ShallowCopy(colors->GetOutput());
vtkBitArray *selectionMask=vtkBitArray::New();
selectionMask->SetName("mask");
selectionMask->SetNumberOfComponents(1);
selectionMask->SetNumberOfTuples(selection->GetNumberOfPoints());
// Initially, everything is selected
vtkIdType i=0;
vtkIdType c=selectionMask->GetNumberOfTuples();
while(i<c)
{
selectionMask->SetValue(i,true);
++i;
}
selection->GetPointData()->AddArray(selectionMask);
selectionMask->Delete();
vtkGlyph3DMapper *glypher2=vtkGlyph3DMapper::New();
// glypher->SetNestedDisplayLists(0);
glypher2->SetMasking(1);
glypher2->SetMaskArray("mask");
glypher2->SetInputData(selection);
glypher2->SetScaleFactor(1.5);
glypher2->SetSourceConnection(squad->GetOutputPort());
glyphActor2->SetMapper(glypher2);
glypher2->Delete();
// Standard rendering classes
renderer = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(renderer);
renWin->SetMultiSamples(0);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
//set up the view
renderer->SetBackground(0.2,0.2,0.2);
renWin->SetSize(600,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);
renderer->AddActor(glyphActor1);
renderer->AddActor(glyphActor2);
glyphActor2->SetPosition(2,0,0);
glyphActor1->Delete();
glyphActor2->Delete();
//pass pick events to the VisibleGlyphSelector
MyEndPickCommand *cbc=new MyEndPickCommand;
cbc->SetRenderer(renderer);
cbc->SetMask(selectionMask);
cbc->SetDataSet(selection);
rwi->AddObserver(vtkCommand::EndPickEvent,cbc);
cbc->Delete();
////////////////////////////////////////////////////////////
//run the test
renderer->ResetCamera();
renderer->GetActiveCamera()->Zoom(2.0);
renWin->Render();
// areaPicker->AreaPick(0, 0, 241, 160, renderer);
areaPicker->AreaPick(233, 120, 241, 160, renderer);
cbc->Execute(NULL, 0, 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();
selection->Delete();
return !retVal;
}
......@@ -376,7 +376,7 @@ void vtkOpenGLGlyph3DHelper::GlyphRender(
vtkMTimeType pointMTime)
{
// we always tell our triangle VAO to emulate unless we
// have opngl 3.2 to be safe
// have opengl 3.2 to be safe
// this is because it seems that GLEW_ARB_vertex_array_object
// does not always handle the attributes for GLEW_ARB_instanced_arrays
this->Primitives[PrimitiveTris].VAO->SetForceEmulation(
......@@ -392,7 +392,8 @@ void vtkOpenGLGlyph3DHelper::GlyphRender(
if (actor->GetProperty()->GetRepresentation() == VTK_SURFACE &&
!selector && GLEW_ARB_instanced_arrays)
!selector && !ren->GetRenderWindow()->GetIsPicking()
&& GLEW_ARB_instanced_arrays)
{
this->GlyphRenderInstances(ren, actor, numPts,
colors, matrices, normalMatrices, pointMTime);
......@@ -414,7 +415,7 @@ void vtkOpenGLGlyph3DHelper::GlyphRender(
for (vtkIdType inPtId = 0; inPtId < numPts; inPtId++)
{
if (selecting_points)
if (selector)
{
selector->RenderAttributeId(pickIds[inPtId]);
}
......@@ -512,7 +513,7 @@ void vtkOpenGLGlyph3DHelper::SetMapperShaderParameters(vtkOpenGLHelper &cellBO,
this->Superclass::SetMapperShaderParameters(cellBO,ren,actor);
vtkHardwareSelector* selector = ren->GetSelector();
if (selector && selector->GetCurrentPass() == vtkHardwareSelector::ID_LOW24)
if (selector)
{
cellBO.Program->SetUniform3f("mapperIndex", selector->GetPropColorValue());
}
......
......@@ -127,10 +127,8 @@ class vtkOpenGLGlyph3DMapper::vtkOpenGLGlyph3DMapperSubArray
public:
std::map<size_t, vtkOpenGLGlyph3DMapper::vtkOpenGLGlyph3DMapperEntry *> Entries;
vtkTimeStamp BuildTime;
bool LastSelectingState;
vtkOpenGLGlyph3DMapperSubArray()
{
this->LastSelectingState = false;
};
~vtkOpenGLGlyph3DMapperSubArray()
{
......@@ -230,20 +228,12 @@ void vtkOpenGLGlyph3DMapper::Render(vtkRenderer *ren, vtkActor *actor)
this->SetupColorMapper();
vtkHardwareSelector* selector = ren->GetSelector();
bool selecting_points = selector && (selector->GetFieldAssociation() ==
vtkDataObject::FIELD_ASSOCIATION_POINTS);
if (selector)
{
selector->BeginRenderProp();
}
if (selector && !selecting_points)
{
// Selecting some other attribute. Not supported.
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
}
vtkDataObject* inputDO = this->GetInputDataObject(0, 0);
// Check input for consistency
......@@ -342,11 +332,6 @@ void vtkOpenGLGlyph3DMapper::Render(vtkRenderer *ren, vtkActor *actor)
iter->Delete();
}
if (selector && !selecting_points)
{
// Selecting some other attribute. Not supported.
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
}
if (selector)
{
selector->EndRenderProp();
......@@ -490,14 +475,11 @@ void vtkOpenGLGlyph3DMapper::Render(
}
vtkHardwareSelector* selector = ren->GetSelector();
bool selecting_points = selector && (selector->GetFieldAssociation() ==
vtkDataObject::FIELD_ASSOCIATION_POINTS);
// rebuild all entries for this DataSet if it
// has been modified
if (subarray->BuildTime < dataset->GetMTime() ||
subarray->BuildTime < this->GetMTime() ||
subarray->LastSelectingState != selecting_points )
subarray->BuildTime < this->GetMTime())
{
rebuild = true;
}
......@@ -525,8 +507,7 @@ void vtkOpenGLGlyph3DMapper::Render(
// rebuild all sources for this dataset
if (rebuild)
{
this->RebuildStructures(subarray, numPts, actor, dataset, maskArray,
selecting_points);
this->RebuildStructures(subarray, numPts, actor, dataset, maskArray);
}
// for each subarray
......@@ -592,7 +573,7 @@ void vtkOpenGLGlyph3DMapper::Render(
bool primed = false;
for (vtkIdType inPtId = 0; inPtId < entry->NumberOfPoints; inPtId++)
{
if (selecting_points)
if (selector)
{
selector->RenderAttributeId(entry->PickIds[inPtId]);
}
......@@ -637,8 +618,7 @@ void vtkOpenGLGlyph3DMapper::RebuildStructures(
vtkIdType numPts,
vtkActor* actor,
vtkDataSet* dataset,
vtkBitArray *maskArray,
bool selecting_points)
vtkBitArray *maskArray)
{
double den = this->Range[1] - this->Range[0];
if (den == 0.0)
......@@ -934,7 +914,6 @@ void vtkOpenGLGlyph3DMapper::RebuildStructures(
}
}
subarray->LastSelectingState = selecting_points;
subarray->BuildTime.Modified();
trans->Delete();
normalTrans->Delete();
......
......@@ -46,7 +46,6 @@ public:
/**
* Method initiates the mapping process. Generally sent by the actor
* as each frame is rendered.
* Its behavior depends on the value of SelectMode.
*/
void Render(vtkRenderer *ren, vtkActor *a) VTK_OVERRIDE;
......@@ -86,7 +85,7 @@ protected:
*/
virtual void RebuildStructures(vtkOpenGLGlyph3DMapperSubArray *entry,
vtkIdType numPts, vtkActor* actor, vtkDataSet* dataset,
vtkBitArray *maskArray, bool selecting_points);
vtkBitArray *maskArray);
vtkWeakPointer<vtkWindow> LastWindow; // Window used for previous render.
......
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