Problem 2 probably isn't a bug. The red book says that, "OpenGL is not a pixel-exact specificaiton" and for this reason the exact pixels and thus cells returned by the selector may vary. The TestAreaSelection test can produce slightly different images on Mesa and a graphics card because of this for example.
<br><br>Problem 1 probably is a bug and I'll take a look.<br><br><div><span class="gmail_quote">On 3/23/07, <b class="gmail_sendername">Lim, Theodore</b> <<a href="mailto:T.Lim@hw.ac.uk">T.Lim@hw.ac.uk</a>> wrote:
</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>
<div dir="ltr">
<div dir="ltr"><font color="#000000" face="Arial" size="2">Hi David, and fellow
vtk-er's,</font></div>
<div dir="ltr"><font face="Arial" size="2"></font> </div>
<div dir="ltr"><font face="Arial" size="2">I've made a test to check the changes. What
i've done is to create a bounding sphere that encompass a test object. For
each long-lat intersection of the sphere source, I re-locate the current camera
position to a long-lat intersection and set the camera's focal point to the
center of the bounding sphere. Once the camera is in its new position, it is
reset so as to view the whole object. Then the visible test is
performed.</font></div>
<div dir="ltr"><font face="Arial" size="2"></font> </div>
<div dir="ltr"><font face="Arial" size="2">The OffScreen works great but now i
have a problem with OnScreen rendering. I've attached my code
below.</font></div>
<div dir="ltr"><font face="Arial" size="2"></font> </div>
<div dir="ltr"><font face="Arial" size="2">Test subject:</font></div>
<div dir="ltr"><font face="Arial" size="2"></font> </div>
<div dir="ltr"><font face="Arial" size="2">Using STL model - 424000-IDGH.stl (located
in vtkData branch)</font></div>
<div dir="ltr"><font face="Arial" size="2"></font> </div>
<div dir="ltr"><font face="Arial" size="2">Problem 1:</font></div>
<div dir="ltr"><font face="Arial" size="2"></font> </div>
<div dir="ltr"><font face="Arial" size="2">When </font><font face="Arial" size="2">renWin->SetOffScreenRendering(0) , the first time through the
'for' loop (i.e. when i = 0), vtkVisibleCellSelector works fine. The number of
cells returned is 2114 (based on the window size 800x800).</font></div>
<div dir="ltr"><font face="Arial" size="2"></font> </div>
<div dir="ltr"><font face="Arial" size="2">Then, for any value of i > 0,
vtkVisibleCellSelector always returns 1 cell. Why??</font></div>
<div dir="ltr"><font face="Arial" size="2"></font> </div>
<div dir="ltr"><font face="Arial" size="2">Problem 2:</font></div>
<div dir="ltr"><font face="Arial" size="2"></font> </div>
<div dir="ltr"><font face="Arial" size="2">When
renWin->SetOffScreenRendering(1), and i = 0, the number of cells returned is
2116. Shouldn't this be the same as when renWin->SetOffScreenRendering(0),
i.e. return 2114 cells??</font></div>
<div dir="ltr"><font face="Arial" size="2"></font> </div>
<div dir="ltr"><font face="Arial" size="2">For any value i > 0, there are always
cells being returned (Yay!). Some results: When i = 1 (3448 cells), i = 2 (2574
cells). No complaints here, i'm getting cells back eventhough there are a couple
extra (perhaps?).</font></div>
<div dir="ltr"><font face="Arial" size="2"></font> </div>
<div dir="ltr"><font face="Arial" size="2">Would appreciate if you or anyone else can
spot the errors i'm getting and how to solve it.</font></div>
<div dir="ltr"><font face="Arial" size="2"></font> </div>
<div dir="ltr"><font face="Arial" size="2">Many thanks in advance, </font></div>
<div dir="ltr"><font face="Arial" size="2">Theo.</font></div>
<div dir="ltr"><font face="Arial" size="2"></font> </div>
<div dir="ltr"><font face="Arial" size="2">//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
</font></div>
<div dir="ltr"><font face="Arial" size="2"></font> </div>
<div dir="ltr"><font color="#000000" face="Arial" size="2">// TestVCellSelector.cpp :
Defines the entry point for the console application.<br>//<br>#include
<stdio.h><br>#include <stdlib.h><br>#include
<iostream><br>#include <fstream><br>#include
<tchar.h></font></div>
<div dir="ltr"><font color="#000000" face="Arial" size="2">#include
"vtkRenderer.h"<br>#include "vtkRenderWindow.h"<br>#include
"vtkRenderWindowInteractor.h"<br>#include "vtkSphereSource.h"<br>#include
"vtkPolyDataMapper.h"<br>#include "vtkActor.h"<br>#include
"vtkInteractorStyleTrackballCamera.h"<br>#include
"vtkCallbackCommand.h"<br>#include "vtkVisibleCellSelector.h"<br>#include
"vtkSelection.h"<br>#include "vtkExtractSelectedPolyDataIds.h"<br>#include
"vtkIdTypeArray.h"<br>#include "vtkCamera.h"<br>#include
"vtkSmartPointer.h"</font></div>
<div dir="ltr"><font color="#000000" face="Arial" size="2">#include
"vtkSTLReader.h"<br>#include "vtkProperty.h"<br>#include
"vtkPoints.h"</font></div>
<div dir="ltr"><font color="#000000" face="Arial" size="2">#include
"vtkWin32OpenGLRenderWindow.h"<br>#include
"vtkWindowToImageFilter.h"<br>#include "vtkJPEGWriter.h"</font></div>
<div dir="ltr"><font color="#000000" face="Arial" size="2">#include
"vtkUnsignedCharArray.h"</font></div>
<div dir="ltr"><font color="#000000" face="Arial" size="2">using namespace
std;</font></div>
<div dir="ltr"><font color="#000000" face="Arial" size="2">int main()<br>{<br> //
Standard rendering classes<br> vtkSmartPointer<vtkRenderer> renderer
= vtkSmartPointer<vtkRenderer>::New();<br> // set up the
view<br> renderer->GetActiveCamera()->SetViewUp(0, 1,
0);<br> renderer->SetBackground(0.0,0.0,0.0);<br> // set render
window<br> vtkSmartPointer<vtkRenderWindow> renWin =
vtkSmartPointer<vtkRenderWindow>::New();<br> renWin->AddRenderer(renderer);<br> renWin->SetSize(800,800);<br> /***********************************/<br> //
In 'for' loop below:<br> // Works great offscreen with
vtkVisibleCellSelector
(huzzahhh!)<br> //renWin->SetOffScreenRendering(1);<br> // Works
1st time when set onscreen, faults after that (returns only 1 cell --
why??!!).<br> renWin->SetOffScreenRendering(0);<br> /***********************************/<br> //
set interactor<br> vtkSmartPointer<vtkRenderWindowInteractor> iren =
vtkSmartPointer<vtkRenderWindowInteractor>::New();<br> iren->SetRenderWindow(renWin);
<br> //use the trackball camera interactor
style<br> vtkSmartPointer<vtkInteractorStyleTrackballCamera> style =
vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();<br> iren->SetInteractorStyle(style);</font></div>
<div dir="ltr"><font color="#000000" face="Arial" size="2"> ////////////////////////////////////////////////////////////<br> //
load test part<br> vtkSmartPointer<vtkSTLReader> reader =
vtkSmartPointer<vtkSTLReader>::New();<br> reader->SetFileName("C:/VTKData/Data/42400-IDGH.stl");</font></div>
<div dir="ltr"><font color="#000000" face="Arial" size="2"> // set on-screen
mapper<br> vtkSmartPointer<vtkPolyDataMapper> map1 =
vtkSmartPointer<vtkPolyDataMapper>::New(); <br> map1->SetInput(reader->GetOutput());<br> map1->Update();</font></div>
<div dir="ltr"><font color="#000000" face="Arial" size="2"> // set on-screen
actor<br> vtkSmartPointer<vtkActor> act1 =
vtkSmartPointer<vtkActor>::New();<br> act1->SetMapper(map1);<br> renderer->AddActor(act1);</font></div>
<div dir="ltr"><font color="#000000" face="Arial" size="2"> // make a scaning
sphere template<br> int res = 10;<br> double diagonal =
act1->GetLength();<br> double *center =
act1->GetCenter();<br> vtkSmartPointer<vtkSphereSource> S =
vtkSmartPointer<vtkSphereSource>::New();<br> S->SetThetaResolution(res);<br> S->SetPhiResolution(res);<br> S->SetRadius(diagonal);<br> S->SetCenter(center);<br> S->Update();</font></div>
<div dir="ltr"><font color="#000000" face="Arial" size="2"> // Get longLat
intersect points<br> vtkSmartPointer<vtkPoints> pts =
S->GetOutput()->GetPoints();</font></div>
<div dir="ltr"><font color="#000000" face="Arial" size="2"> // Number of visible
cells<br> vtkIdType numCells;</font></div>
<div dir="ltr"><font color="#000000" face="Arial" size="2"> // Set visible cell
selector<br> vtkSmartPointer<vtkVisibleCellSelector> sel1 =
vtkSmartPointer<vtkVisibleCellSelector>::New();<br> sel1->SetRenderer(renderer);<br> sel1->SetRenderPasses(0,1,0,1,1);<br> int
*size =
renderer->GetSize();<br> sel1->SetArea(size[0],size[1],size[2],size[3]);</font></div>
<div dir="ltr"><font color="#000000" face="Arial" size="2"> // Get visible cell
scan at each long-Lat intersection<br> for (int i = 0; i <
pts->GetNumberOfPoints(); i++)<br> {<br> // set camera
position at long-lat
intersection <br> renderer->GetActiveCamera()->SetPosition(pts->GetPoint(i));<br> renderer->GetActiveCamera()->SetFocalPoint(center);<br> renderer->ResetCamera();</font></div>
<div dir="ltr"><font color="#000000" face="Arial" size="2"> // Update view
when not using offscreen, so can see orientation of camera relative to viewed
object<br> if
(!renWin->GetOffScreenRendering())<br> renWin->Render();</font></div>
<div dir="ltr"><font color="#000000" face="Arial" size="2"> //
Test...<br> ////////////////////////////////////////////////////////////<br> <br> //
grab all visible cells in render
window<br> sel1->Select();</font></div>
<div dir="ltr"><font color="#000000" face="Arial" size="2"> // get selected
ids<br> vtkSelection *res1 =
vtkSelection::New();<br> sel1->GetSelectedIds(res1);<br> //
extract cell id list<br> vtkSelection *cellids =
res1->GetChild(0);<br> // get number of visible cells
<br> vtkIdTypeArray *idArray =
vtkIdTypeArray::SafeDownCast(cellids->GetSelectionList());<br> numCells
=
idArray->GetNumberOfComponents()*idArray->GetNumberOfTuples();</font></div>
<div dir="ltr"><font color="#000000" face="Arial" size="2"> ////////////////////////////////////////////////////////////</font></div>
<div dir="ltr"><font color="#000000" face="Arial" size="2"> res1->Delete();</font></div>
<div dir="ltr"><font color="#000000" face="Arial" size="2"> }</font></div>
<div dir="ltr"><font color="#000000" face="Arial" size="2"> //
render <br> renWin->Render();</font></div>
<div dir="ltr"><font color="#000000" face="Arial" size="2"> //
start<br> iren->Initialize();<br> iren->Start();</font></div>
<div dir="ltr"><font color="#000000" face="Arial" size="2"> return
0;<br>}<br></font></div></div>
<div dir="ltr"><br>
<hr>
<font face="Tahoma" size="2"><b>From:</b> David E DeMarle
[mailto:<a href="mailto:dave.demarle@kitware.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">dave.demarle@kitware.com</a>]<br><b>Sent:</b> Thu 22/03/2007
19:12<br><b>To:</b> Lim, Theodore <br><b>Cc:</b> vtk-users<br><b>Subject:</b>
Re: [vtkusers] Win32 OffScreen Rendering and Visibility cell
selector<br></font><br></div>
<div>I've just committed a change to vtkOpenGLRenderWindow which appears to fix
it. The change is to return default values if the window isn't mapped like
getColorDepth does.<br><br>cheers<br>Dave DeMarle<br><br>
<div><span class="gmail_quote">On 3/22/07, <b class="gmail_sendername">David E
DeMarle</b> <<a href="mailto:dave.demarle@kitware.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">dave.demarle@kitware.com</a>>
wrote:</span>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hmmm,
the program looks ok to me, with the exception of two calls to a "render"
instead of "ofsrender".<br>I will try cell selection with offscreen rendering
on windows and see if I can reproduce the problem. <br><br>cheers<br>Dave
DeMarle<br><br><br>
<div>
<div><span><span class="gmail_quote">On 3/20/07,
<b class="gmail_sendername">Lim, Theodore</b> <<a href="mailto:T.Lim@hw.ac.uk" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> T.Lim@hw.ac.uk</a>>
wrote:</span></span></div>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>
<div><span>
<div dir="ltr">
<div dir="ltr"><font color="#000000" face="Arial" size="2"></font>Hi,</div>
<div dir="ltr"> </div>
<div dir="ltr">Not sure how to put this but here goes...</div>
<div dir="ltr"> </div>
<div dir="ltr">I'm trying to get get visible cell data for a series of camera
positions and would like to do this using the Win32 offscreen rendering
capabilities.</div>
<div dir="ltr"> </div>
<div dir="ltr">However, i discovered that the offscreen render window color
buffer size returns all 0 values. This seems to be the reason why the
visible cell selector fails. Is there a way to set (or force) values into
it?</div>
<div dir="ltr"> </div>
<div dir="ltr">Or rather, can the new class vtkVisibilityCellSelector be used
in Offscreen rendering mode? And if so, how can this be achieved. I've
attached the code which i'm testing below.</div>
<div dir="ltr"> </div>
<div dir="ltr">One note: i compiled with cmake option VTK_USE_OFFSCREEN set to
'Off' as this caused the vtkMFC examples (i.e. vtkDLG, vtkSDI,
vtkMDI) to crash. It also caused the same response to my own VTK-MFC
app. Not sure if this has anything to do with it not being able to use
Offscreen. In the test code below, i use the vtkWindowToImageFilter to grab
a snapshot of the offscreen render window and the results was as
expected.</div>
<div dir="ltr"> </div>
<div dir="ltr">Any help would be greatly appreciated.</div>
<div dir="ltr"> </div>
<div dir="ltr">Many thanks, Theo.</div>
<div dir="ltr"> </div>
<div dir="ltr">/**************************************************************************************************/</div>
<div dir="ltr">int main()<br>{<br> //Load
model<br> vtkSmartPointer<vtkSTLReader> reader =
vtkSmartPointer<vtkSTLReader>::New();<br> reader->SetFileName("C:/Model/Data/MillCut.stl");</div>
<div dir="ltr"> vtkSmartPointer<vtkPolyDataMapper> map1 =
vtkSmartPointer<vtkPolyDataMapper>::New(); <br> map1->SetInput(reader->GetOutput());</div>
<div dir="ltr"><br> // set up offscreen
renderer<br> vtkSmartPointer<vtkRenderer> ofsrenderer =
vtkSmartPointer<vtkRenderer>::New();<br> ofsrenderer->SetBackground(0.0,0.0,0.0);
<br> vtkSmartPointer<vtkRenderWindow> ofsrenWin =
vtkSmartPointer<vtkRenderWindow>::New();<br> ofsrenWin->AddRenderer(ofsrenderer);<br> ofsrenWin->SetSize(800,800);<br> ofsrenWin->SetOffScreenRendering(1);</div>
<div dir="ltr"> // set
interactor<br> vtkSmartPointer<vtkRenderWindowInteractor> iren =
vtkSmartPointer<vtkRenderWindowInteractor>::New();<br> iren->SetRenderWindow(ofsrenWin);
</div>
<div dir="ltr"><br> //set up the
view<br> renderer->GetActiveCamera()->SetViewUp(0, 1,
0);<br> renderer->SetBackground(0.0,0.0,0.0);
<br> <br> <br> // set
actor<br> vtkSmartPointer<vtkActor> act1 =
vtkSmartPointer<vtkActor>::New();<br> act1->SetMapper(map1);</div>
<div dir="ltr"> // add actor to renderer<br> double diagonal =
act1->GetLength();<br> double *center =
act1->GetCenter(); <br> ofsrenderer->AddActor(act1);<br> ofsrenderer->GetActiveCamera()->SetFocalPoint(center);<br> ofsrenderer->GetActiveCamera()->SetPosition(20,
-20, -27);<br> ofsrenderer->ResetCamera();</div>
<div dir="ltr"><br> ofsrenWin->Render();</div>
<div dir="ltr"> //-----------------------------------------------<br> //
check offscreen render window...<br> int
rgba[4];<br> ofsrenWin->GetColorBufferSizes(rgba);</div>
<div dir="ltr"> vtkSmartPointer<vtkWindowToImageFilter> wif =
vtkSmartPointer<vtkWindowToImageFilter>::New();//<br> wif->SetInput(ofsrenWin);<br> wif->Update(); </div>
<div dir="ltr"> vtkSmartPointer<vtkJPEGWriter> jpgw =
vtkSmartPointer<vtkJPEGWriter>::New();<br> jpgw->SetInput(wif->GetOutput());<br> jpgw->SetQuality(100);<br> jpgw->SetFileName("D:/Projects/VTK/testoffscreen.jpg");<br> jpgw->Write();</div>
<div dir="ltr"> //-----------------------------------------------</div>
<div dir="ltr"><br> // get visible
cells<br> vtkSmartPointer<vtkVisibleCellSelector> sel1 =
vtkSmartPointer<vtkVisibleCellSelector>::New();<br> sel1->SetRenderer(ofsrenderer);</div>
<div dir="ltr"> // grab everything
in the render window viewport<br> int *size =
ofsrenderer->GetRenderWindow()->GetSize();<br> sel1->SetRenderPasses(0,1,0,1,1);<br> sel1->SetArea(size[0],size[1],size[2],size[3]);<br> sel1->Select();<br> vtkSmartPointer<vtkSelection>
res1 =
vtkSmartPointer<vtkSelection>::New();<br> sel1->GetSelectedIds(res1);</div>
<div dir="ltr"> vtkSmartPointer<vtkSelection> cellids =
res1->GetChild(0);<br> vtkSmartPointer<vtkExtractSelectedPolyDataIds>
extr =
vtkSmartPointer<vtkExtractSelectedPolyDataIds>::New();<br>
if (cellids)<br>
{<br>
extr->SetInput(1,
act1->GetMapper()->GetInput());<br>
extr->SetInput(0,
cellids);<br>
extr->Update();<br>
sMap->SetInput(extr->GetOutput());<br>
}<br>
else<br>
{<br> cerr <<
"Empty color buffer selection -" <<
endl;<br> cerr
<< "Check display color depth. Must be at least 24 bit." <<
endl;<br>
sMap->SetInput(emptyPD);<br>
}</div>
<div dir="ltr"> ////////////////////////////////////////////////////////////</div>
<div dir="ltr"> ofsrenWin->Render();</div>
<div dir="ltr"><br> // Set the user method (bound to key
'u')<br> iren->Initialize();<br> iren->Start();</div>
<div dir="ltr"><br> return 0;<br>}</div>
<div dir="ltr"> </div>
<div dir="ltr"> </div></div></span></div></div><br>_______________________________________________<br>This
is the private VTK discussion list.<br>Please keep messages on-topic. Check
the FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.vtk.org/Wiki/VTK_FAQ</a><br>Follow this link to
subscribe/unsubscribe:<br><a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.vtk.org/mailman/listinfo/vtkusers
</a><br><br></blockquote></div><br></blockquote></div><br></div></div></blockquote></div><br>