That did the trick!! It now works every time no matter how far I move the object or zoom, etc.<br><br>Thanks Joe!!<br><br>-Kerry<br><br><div class="gmail_quote">On Thu, May 22, 2008 at 3:08 PM, Johannes Heitz <<a href="mailto:j.heitz@mediri.com">j.heitz@mediri.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I am not saying it might be a solution... Been there, done that ;(<br>
<br>
double bounds[6];<br>
pRenderer->ComputeVisiblePropBounds(bounds);<br>
pRenderer->ResetCameraClippingRange(bounds);<br>
<br>
Would in theory get the extent of the currently visible "actors" and (re)set the clipping range accordingly.<br><font color="#888888">
<br>
J.<br>
</font><br><br>
// Quick (and unclean) test app to find out how and when to get rendered actors to update<br>
// Top of the UI -> wxVTK Window with 8 cone actors<br>
// Bottom of UI -> wxTextCtrl to type commands into<br>
// Commands are<br>
// either a number from 0 to 7 followed by an action<br>
// Actions are "hide", "show", "color", "hop" and the numbers make the cone # x perform that action<br>
// or "renderon", "renderoff", "on" or "off", (all show that I was wrong ;P),<br>
// "boundson", "boundsoff" (use the set clipping range or not)<br>
// "allcolor", "allhop" (color, move all actors at once) or<br>
// clip NEAR FAR (setting the current cameras clipping range)<br>
<br>
// What this might show is that...<br>
<br>
// vtkRenderer->ComputeVisiblePropBounds(bounds);<br>
// vtkRenderer->ResetCameraClippingRange(bounds);<br>
<br>
// might 'render' all actors no matter what the clipping range is :|<br>
<br>
// Commands are 'sent' by hitting return<br>
<br>
<br>
// For compilers that support precompilation, includes "wx/wx.h".<br>
#include "wx/wxprec.h"<br>
<br>
#ifdef __BORLANDC__<br>
#pragma hdrstop<br>
#endif<br>
<br>
// for all others, include the necessary headers (this file is usually all you<br>
// need because it includes almost all "standard" wxWindows headers)<br>
#ifndef WX_PRECOMP<br>
#include "wx/wx.h"<br>
#endif<br>
<br>
#include "wxVTKRenderWindowInteractor.h"<br>
#include "vtkCamera.h"<br>
#include "vtkRenderer.h"<br>
#include "vtkRenderWindow.h"<br>
#include "vtkConeSource.h"<br>
#include "vtkPolyDataMapper.h"<br>
#include "vtkActor.h"<br>
#include "vtkPolyDataReader.h"<br>
#include "vtkProperty.h"<br>
<br>
#include "vtkPNGReader.h"<br>
#include "vtkImageMapper.h"<br>
#include "vtkImageShiftScale.h"<br>
#include "vtkInteractorStyleImage.h"<br>
#include "vtkActor2D.h"<br>
<br>
#include "vtkImageViewer2.h"<br>
#include "vtkImageData.h"<br>
#include "vtkTesting.h"<br>
#include "vtkTestUtilities.h"<br>
<br>
<br>
// the application icon<br>
#ifndef __WXMSW__<br>
#include "mondrian.xpm"<br>
#endif<br>
<br>
class MyApp;<br>
class MyFrame;<br>
<br>
// Define a new application type, each program should derive a class from wxApp<br>
class MyApp : public wxApp<br>
{<br>
public:<br>
// this one is called on application startup and is a good place for the app<br>
// initialization (doing it here and not in the ctor allows to have an error<br>
// return: if OnInit() returns false, the application terminates)<br>
virtual bool OnInit();<br>
};<br>
<br>
// Define a new frame type: this is going to be our main frame<br>
class MyFrame : public wxFrame<br>
{<br>
public:<br>
// ctor(s)<br>
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);<br>
~MyFrame();<br>
<br>
// event handlers (these functions should _not_ be virtual)<br>
void OnQuit(wxCommandEvent& event);<br>
void OnAbout(wxCommandEvent& event);<br>
void OnTextInput(wxCommandEvent& event);<br>
void doCommand(wxString strCommand);<br>
protected:<br>
void Setup();<br>
void Cleanup();<br>
<br>
private:<br>
wxVTKRenderWindowInteractor* m_pVTKWindow;<br>
vtkRenderer* pRenderer;<br>
vtkRenderWindow* pRenderWindow;<br>
vtkPolyDataMapper* pConeMapper[8];<br>
vtkActor* pConeActor[8];<br>
vtkConeSource* pConeSource[8];<br>
wxTextCtrl* m_pTextCtrl;<br>
wxPanel* panel;<br>
<br>
bool m_autorender;<br>
bool m_maxbounds;<br>
<br>
private:<br>
// any class wishing to process wxWindows events must use this macro<br>
DECLARE_EVENT_TABLE()<br>
};<br>
<br>
// IDs for the controls and the menu commands<br>
enum<br>
{<br>
// menu items<br>
Minimal_Quit = 1,<br>
Minimal_About<br>
};<br>
<br>
#define MY_FRAME 101<br>
#define MY_VTK_WINDOW 102<br>
#define ID_TEXT 103<br>
<br>
// the event tables connect the wxWindows events with the functions (event<br>
// handlers) which process them. It can be also done at run-time, but for the<br>
// simple menu events like this the static method is much simpler.<br>
BEGIN_EVENT_TABLE(MyFrame, wxFrame)<br>
EVT_MENU(Minimal_Quit, MyFrame::OnQuit)<br>
EVT_MENU(Minimal_About, MyFrame::OnAbout)<br>
EVT_TEXT_ENTER(ID_TEXT, MyFrame::OnTextInput)<br>
END_EVENT_TABLE()<br>
<br>
// Create a new application object: this macro will allow wxWindows to create<br>
// the application object during program execution (it's better than using a<br>
// static object for many reasons) and also declares the accessor function<br>
// wxGetApp() which will return the reference of the right type (i.e. MyApp and<br>
// not wxApp)<br>
IMPLEMENT_APP(MyApp)<br>
<br>
// 'Main program' equivalent: the program execution "starts" here<br>
bool MyApp::OnInit()<br>
{<br>
<br>
MyFrame *frame = new MyFrame(_T("wxWindows-VTK App"),<br>
wxPoint(50, 50), wxSize(450, 340));<br>
<br>
frame->Show(TRUE);<br>
<br>
return TRUE;<br>
}<br>
<br>
// frame constructor<br>
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)<br>
: wxFrame((wxFrame *)NULL, -1, title, pos, size)<br>
{<br>
#ifdef __WXMAC__<br>
// we need this in order to allow the about menu relocation, since ABOUT is<br>
// not the default id of the about menu<br>
wxApp::s_macAboutMenuItemId = Minimal_About;<br>
#endif<br>
<br>
SetIcon(wxICON(mondrian));<br>
<br>
wxMenu *menuFile = new wxMenu(_T(""), wxMENU_TEAROFF);<br>
wxMenu *helpMenu = new wxMenu;<br>
<br>
helpMenu->Append(Minimal_About, _T("&About...\tCtrl-A"), _T("Show about dialog"));<br>
menuFile->Append(Minimal_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));<br>
<br>
wxMenuBar *menuBar = new wxMenuBar();<br>
menuBar->Append(menuFile, _T("&File"));<br>
menuBar->Append(helpMenu, _T("&Help"));<br>
<br>
SetMenuBar(menuBar);<br>
<br>
<br>
<br>
#if wxUSE_STATUSBAR<br>
// create a status bar just for fun (by default with 1 pane only)<br>
CreateStatusBar(2);<br>
SetStatusText(_T("Zoom out to see cones"));<br>
#endif // wxUSE_STATUSBAR<br>
<br>
panel = new wxPanel(this, -1);<br>
m_pVTKWindow = new wxVTKRenderWindowInteractor(panel, MY_VTK_WINDOW);<br>
m_pVTKWindow->UseCaptureMouseOn();<br>
m_pTextCtrl = new wxTextCtrl(panel, ID_TEXT, "", wxDefaultPosition, wxDefaultSize,wxTE_PROCESS_ENTER/*|wxTE_MULTILINE*/);<br>
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);<br>
vbox->Add(m_pVTKWindow, 2,wxEXPAND);<br>
vbox->Add(m_pTextCtrl, 1,wxEXPAND);<br>
panel->SetSizer(vbox);<br>
m_maxbounds = false;<br>
m_autorender = false;<br>
Setup();<br>
}<br>
<br>
MyFrame::~MyFrame()<br>
{<br>
Cleanup();<br>
}<br>
<br>
<br>
void MyFrame::Setup()<br>
{<br>
pRenderer = vtkRenderer::New();<br>
pRenderWindow = m_pVTKWindow->GetRenderWindow();<br>
pRenderWindow->AddRenderer(pRenderer);<br>
<br>
for(int iLoop = 0; iLoop < 8; iLoop++)<br>
{<br>
pConeMapper[iLoop] = vtkPolyDataMapper::New();<br>
pConeActor[iLoop] = vtkActor::New();<br>
pConeSource[iLoop] = vtkConeSource::New();<br>
pConeSource[iLoop]->SetAngle(60-(5*iLoop));<br>
pConeSource[iLoop]->SetResolution(2*(iLoop+1));<br>
pConeMapper[iLoop]->SetInput(pConeSource[iLoop]->GetOutput());<br>
pConeActor[iLoop]->SetMapper(pConeMapper[iLoop]);<br>
pConeActor[iLoop]->SetPosition(iLoop*(rand()%2==1?-1:1),iLoop*(rand()%2==1?-1:1),iLoop*(rand()%2==1?-1:1));<br>
pRenderer->AddActor(pConeActor[iLoop]);<br>
}<br>
<br>
pRenderer->SetBackground(0.4,0.4,0.4);<br>
pRenderer->GetActiveCamera()->Zoom(1.0);<br>
pRenderer->GetActiveCamera()->SetClippingRange(1,1000);<br>
}<br>
<br>
void MyFrame::Cleanup()<br>
{<br>
// No check for != 0 and no try/catch<br>
for(int iLoop = 0; iLoop < 8; iLoop++)<br>
{<br>
pConeMapper[iLoop]->Delete();<br>
pConeActor[iLoop]->Delete();<br>
pConeSource[iLoop]->Delete();<br>
}<br>
pRenderer->Delete();<br>
m_pVTKWindow->Delete();<br>
}<br>
<br>
<br>
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))<br>
{<br>
Close(TRUE);<br>
}<br>
<br>
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))<br>
{<br>
wxString msg;<br>
msg.Printf( _T("This is the about dialog of wx-vtk sample.\n"));<br>
wxMessageBox(msg, _T("About wx-vtk"), wxOK | wxICON_INFORMATION, this);<br>
}<br>
<br>
void MyFrame::OnTextInput(wxCommandEvent& event)<br>
{<br>
if (event.GetEventType() == wxEVT_COMMAND_TEXT_ENTER)<br>
{<br>
doCommand(m_pTextCtrl->GetValue());<br>
m_pTextCtrl->Clear();<br>
}<br>
event.Skip();<br>
}<br>
<br>
void MyFrame::doCommand(wxString strCommand)<br>
{<br>
// This is rather weak but no time for parsing proper...<br>
int iPos = strCommand.Find(" ");<br>
if(-1 != iPos)<br>
{<br>
wxString strOpCode = strCommand.Left(iPos);<br>
strOpCode.Trim();<br>
wxString strRemains = strCommand.Right(strCommand.Length()-iPos);<br>
strRemains.Trim();<br>
<br>
if(!strOpCode.IsEmpty())<br>
{<br>
strOpCode.MakeLower();<br>
if(strOpCode.IsNumber())<br>
{<br>
<br>
double dVal;<br>
strOpCode.ToDouble(&dVal);<br>
if(dVal>7) return;<br>
strRemains.MakeLower();<br>
strRemains.Trim(false);<br>
if(0 == strRemains.CompareTo("hide"))<br>
pRenderer->RemoveActor(pConeActor[(int)dVal]);<br>
if(0 == strRemains.CompareTo("show"))<br>
pRenderer->AddActor(pConeActor[(int)dVal]);<br>
if(0 == strRemains.CompareTo("color"))<br>
pConeActor[(int)dVal]->GetProperty()->SetColor((float)(rand()%10)/10,(float)(rand()%10)/10,(float)(rand()%10)/10);<br>
if(0 == strRemains.CompareTo("hop"))<br>
pConeActor[(int)dVal]->SetPosition(rand()%10*(rand()%2==1?-1:1),rand()%10*(rand()%2==1?-1:1),rand()%10*(rand()%2==1?-1:1));<br>
}<br>
else<br>
{<br>
if(0 == strOpCode.CompareTo("clip"))<br>
{<br>
wxString strNear;<br>
wxString strFar;<br>
wxString strRemains = strCommand.Right(strCommand.Length()-iPos);<br>
strRemains.Trim(true);<br>
strRemains.Trim(false);<br>
int iPos = strRemains.Find(" ");<br>
if(-1 != iPos)<br>
{<br>
strNear = strRemains.Left(iPos);<br>
strFar = strRemains.Right(strRemains.Length()-iPos);<br>
<br>
strNear.Trim(true);<br>
strNear.Trim(false);<br>
strFar.Trim(false);<br>
strFar.Trim(true);<br>
if(!strNear.IsEmpty() && !strFar.IsEmpty())<br>
{<br>
double nearVal;<br>
double farVal;<br>
strNear.ToDouble(&nearVal);<br>
strFar.ToDouble(&farVal);<br>
pRenderer->GetActiveCamera()->SetClippingRange(nearVal, farVal);<br>
}<br>
}<br>
}<br>
}<br>
}<br>
}<br>
else<br>
{<br>
wxString strOpCode = strCommand.Left(iPos);<br>
strOpCode.Trim();<br>
strOpCode.MakeLower();<br>
<br>
if(0 == strOpCode.CompareTo("allcolor"))<br>
{<br>
for(int iLoop = 0; iLoop < 8; iLoop++)<br>
{<br>
pConeActor[iLoop]->GetProperty()->SetColor((float)(rand()%10)/10,(float)(rand()%10)/10,(float)(rand()%10)/10);<br>
}<br>
}<br>
<br>
if(0 == strOpCode.CompareTo("allhop"))<br>
{<br>
for(int iLoop = 0; iLoop < 8; iLoop++)<br>
{<br>
pConeActor[iLoop]->SetPosition(rand()%10*(rand()%2==1?-1:1),rand()%10*(rand()%2==1?-1:1),rand()%10*(rand()%2==1?-1:1));<br>
}<br>
}<br>
<br>
if(0 == strOpCode.CompareTo("on"))<br>
{<br>
m_pVTKWindow->SetRenderWhenDisabled(true);<br>
SetStatusText("RenderWhenDisabled = true");<br>
}<br>
if(0 == strOpCode.CompareTo("off"))<br>
{<br>
m_pVTKWindow->SetRenderWhenDisabled(false);<br>
SetStatusText("RenderWhenDisabled = false");<br>
}<br>
if(0 == strOpCode.CompareTo("renderon"))<br>
{<br>
m_autorender = true;<br>
SetStatusText("AutoRender = on");<br>
}<br>
if(0 == strOpCode.CompareTo("renderoff"))<br>
{<br>
m_autorender = false;<br>
SetStatusText("AutoRender = off");<br>
}<br>
if(0 == strOpCode.CompareTo("boundsoff"))<br>
{<br>
m_maxbounds = false;<br>
SetStatusText("Honor clipping range: use SetClippingRange");<br>
}<br>
if(0 == strOpCode.CompareTo("boundson"))<br>
{<br>
m_maxbounds = true;<br>
SetStatusText("Ignore clipping range: use ComputeVisiblePropBounds");<br>
}<br>
}<br>
<br>
double bounds[6];<br>
<br>
/* DBG<br>
double pos[3];<br>
char tmp[1000];<br>
<br>
for(int iLoop = 0; iLoop < 8; iLoop++)<br>
{<br>
pConeActor[iLoop]->GetBounds(bounds);<br>
pConeActor[iLoop]->GetPosition(pos);<br>
sprintf(tmp,"\r\nActor %i is at %f,%f,%f",iLoop, pos[0],pos[1],pos[2]);<br>
m_pTextCtrl->AppendText(tmp);<br>
sprintf(tmp,"\r\nActor %i bounds %f,%f,%f",iLoop, bounds[0],bounds[1],bounds[2],bounds[3],bounds[4],bounds[5]);<br>
m_pTextCtrl->AppendText(tmp);<br>
}<br>
*/<br>
<br>
if(m_maxbounds)<br>
{<br>
pRenderer->ComputeVisiblePropBounds(bounds);<br>
pRenderer->ResetCameraClippingRange(bounds);<br>
}<br>
<br>
if(m_autorender)<br>
{<br>
m_pVTKWindow->GetRenderWindow()->Render();<br>
}<br>
<br>
}<br></blockquote></div><br>