[vtkusers] Unicode && vtkObjectBase

"Johannes Käfer" jak4.scr at gmx.net
Tue Oct 5 16:15:08 EDT 2004


Hi,

I've encountered something within the current CVS vtk which I consider a
bug.

If you are going to compile the code below (it's actually the unaltered
cone6.cxx file from the vtk examples) in Visual Studio 6.0 with: UNICODE,
_UNICODE added to (Project -> Settings > Tab C++  Preprocessor definitions )
and delete _MBCS, than the linker will output the following error:

Cone6.obj : error LNK2001: unresolved external symbol "public: virtual char
const * __thiscall vtkObjectBase::GetClassNameW(void)const "
(?GetClassNameW at vtkObjectBase@@UBEPBDXZ)
Release/test.exe : fatal error LNK1120: 1 unresolved externals

It has to be noted that without the UNICODE options it works fine. The same
example works perfectly with vtk 4.2 and the UNICODE options ON.

If found a bug-report about UNICODE at the bugtracker at:
http://www.vtk.org/Bug/bug.php?op=show&bugid=602&pos=20. However this
bug-report seems not to be related to my "bug".

So, what do you think?

Greetings
 Johannes

---Code
#include "vtkConeSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkCamera.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkCommand.h"
#include "vtkBoxWidget.h"
#include "vtkTransform.h"
#include "vtkInteractorStyleTrackballCamera.h"

//
// Similar to Cone2.cxx, we define a callback for interaction.
// 
class vtkMyCallback : public vtkCommand
{
public:
  static vtkMyCallback *New() 
    { return new vtkMyCallback; }
  virtual void Execute(vtkObject *caller, unsigned long, void*)
    {
      vtkTransform *t = vtkTransform::New();
      vtkBoxWidget *widget = reinterpret_cast<vtkBoxWidget*>(caller);
      widget->GetTransform(t);
      widget->GetProp3D()->SetUserTransform(t);
      t->Delete();
    }
};

class vtkMyCallback1 : public vtkCommand{
public:
	static vtkMyCallback1* New()
		{ return new vtkMyCallback1; }
	
	//TODO: dirty hack, but otherwise I got a linker error and the function is
of no use here
	//virtual const char *GetClassName() const {return "vtkObjectBase";};

	virtual void Execute(vtkObject *caller, unsigned long, void* ){
		// thoughts: since we are determining here the actor we picked it would be
nice
		// to check how the pick was made (which key)

		//modification
		//kaeferj, 09/11/04
		//adding multiple pick functionality to the program
		vtkCellPicker *picker = (vtkCellPicker *)caller;
		unsigned int k;
		
		double coord[3];
//		picker->GetPickPosition( coord );

/*		// we found an actor
		if( picker->GetActor()!=NULL ){
			vtkActor *pickedActor = picker->GetActor();
			bool foundCandidateActor = false;
			
			pickedSurfaceTreeRemovableActorsIndex = -1;
			//TODO: this if is always true (the variable is set above)
			if( !foundCandidateActor )
				for(k=0;k<surfaceTreeRemovableActors.size();k++)
					if(pickedActor==surfaceTreeRemovableActors[k].actor){
						cout << "Picking on tree component " << k << endl;
						
						pickedSurfaceTreeRemovableActorsIndex = k;

						//modification
						//kaeferj, 09/11/04
						//adding multiple pick functionality to the program
						//we need to check if the component has already been picked
						std::vector<int>::iterator theIterator;
						bool add_actor = true;

						for( theIterator = pickedActors.begin(); theIterator !=
pickedActors.end(); theIterator++){
							if( k == *theIterator ){
								add_actor = false;
								break;
							}
						}

						if( add_actor )
							pickedActors.push_back(k);
						else
							pickedActors.erase( theIterator );
						//end
						
						foundCandidateActor = true;
						// update slice
						dlgUpdateSlice(coord);
						break;
					}
		}
		//modification
		//kaeferj, 09/11/04
		//adding multiple pick functionality to the program
		else{
			// we picked no object --> this means we have to delete every selection
thus far
			// the red boxes are deleted within vtk, we just clear our list.
			pickedActors.erase( pickedActors.begin(), pickedActors.end() );
		}

		//TODO: what is this for?
		if(picker->GetVolume()!=NULL)
		{
			vtkVolume* pickedVolume = picker->GetVolume();
			bool foundCandidateVolume = false;
			if( !foundCandidateVolume )
				for(k=0;k<surfaceTreeRemovableActors.size();k++)
					if(pickedVolume==surfaceTreeRemovableActors[k].volume){
						cout << "Picking on tree component " << k << endl;
						
						pickedSurfaceTreeRemovableActorsIndex = k;
					
						foundCandidateVolume = true;
						break;
					}
		}*/
	}
};

int main( int argc, char *argv[] )
{
  // 
  // Next we create an instance of vtkConeSource and set some of its
  // properties. The instance of vtkConeSource "cone" is part of a
  // visualization pipeline (it is a source process object); it produces
data
  // (output type is vtkPolyData) which other filters may process.
  //
  vtkConeSource *cone = vtkConeSource::New();
  cone->SetHeight( 3.0 );
  cone->SetRadius( 1.0 );
  cone->SetResolution( 10 );
  
  // 
  // In this example we terminate the pipeline with a mapper process object.
  // (Intermediate filters such as vtkShrinkPolyData could be inserted in
  // between the source and the mapper.)  We create an instance of
  // vtkPolyDataMapper to map the polygonal data into graphics primitives.
We
  // connect the output of the cone souece to the input of this mapper.
  //
  vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();
  coneMapper->SetInput( cone->GetOutput() );

  // 
  // Create an actor to represent the cone. The actor orchestrates rendering
  // of the mapper's graphics primitives. An actor also refers to properties
  // via a vtkProperty instance, and includes an internal transformation
  // matrix. We set this actor's mapper to be coneMapper which we created
  // above.
  //
  vtkActor *coneActor = vtkActor::New();
  coneActor->SetMapper( coneMapper );

  //
  // Create the Renderer and assign actors to it. A renderer is like a
  // viewport. It is part or all of a window on the screen and it is
  // responsible for drawing the actors it has.  We also set the background
  // color here.
  //
  vtkRenderer *ren1= vtkRenderer::New();
  ren1->AddActor( coneActor );
  ren1->SetBackground( 0.1, 0.2, 0.4 );

  //
  // Finally we create the render window which will show up on the screen.
  // We put our renderer into the render window using AddRenderer. We also
  // set the size to be 300 pixels by 300.
  //
  vtkRenderWindow *renWin = vtkRenderWindow::New();
  renWin->AddRenderer( ren1 );
  renWin->SetSize( 300, 300 );

  // 
  // The vtkRenderWindowInteractor class watches for events (e.g., keypress,
  // mouse) in the vtkRenderWindow. These events are translated into
  // event invocations that VTK understands (see VTK/Common/vtkCommand.h
  // for all events that VTK processes). Then observers of these VTK
  // events can process them as appropriate.
  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
  iren->SetRenderWindow(renWin);

  //
  // By default the vtkRenderWindowInteractor instantiates an instance
  // of vtkInteractorStyle. vtkInteractorStyle translates a set of events
  // it observes into operations on the camera, actors, and/or properties
  // in the vtkRenderWindow associated with the vtkRenderWinodwInteractor. 
  // Here we specify a particular interactor style.
  vtkInteractorStyleTrackballCamera *style = 
    vtkInteractorStyleTrackballCamera::New();
  iren->SetInteractorStyle(style);

  //
  // Here we use a vtkBoxWidget to transform the underlying coneActor (by
  // manipulating its transformation matrix). Many other types of widgets
  // are available for use, see the documentation for more details.
  //
  // The SetInteractor method is how 3D widgets are associated with the
render
  // window interactor. Internally, SetInteractor sets up a bunch of
callbacks
  // using the Command/Observer mechanism (AddObserver()). The place factor 
  // controls the initial size of the widget with respect to the bounding
box
  // of the input to the widget.
  vtkBoxWidget *boxWidget = vtkBoxWidget::New();
  boxWidget->SetInteractor(iren);
  boxWidget->SetPlaceFactor(1.25);

  //
  // Place the interactor initially. The input to a 3D widget is used to 
  // initially position and scale the widget. The EndInteractionEvent is
  // observed which invokes the SelectPolygons callback.
  //
  boxWidget->SetProp3D(coneActor);
  boxWidget->PlaceWidget();
  vtkMyCallback *callback = vtkMyCallback::New();
  boxWidget->AddObserver(vtkCommand::InteractionEvent, callback);

  //
  // Normally the user presses the "i" key to bring a 3D widget to life.
Here
  // we will manually enable it so it appears with the cone. 
  //
  boxWidget->On();

  //
  // Start the event loop.
  //
  iren->Initialize();
  iren->Start();
  
  //
  // Free up any objects we created. All instances in VTK are deleted by
  // using the Delete() method.
  //
  cone->Delete();
  coneMapper->Delete();
  coneActor->Delete();
  callback->Delete();
  boxWidget->Delete();
  ren1->Delete();
  renWin->Delete();
  iren->Delete();
  style->Delete();

  return 0;
}

-- 
GMX ProMail mit bestem Virenschutz http://www.gmx.net/de/go/mail
+++ Empfehlung der Redaktion +++ Internet Professionell 10/04 +++




More information about the vtkusers mailing list