[vtkusers] unfathomable linker error

Bruce.Lamond at ed.ac.uk Bruce.Lamond at ed.ac.uk
Mon Apr 28 12:51:21 EDT 2003


Hi there,
I'm trying to create a subclass of vtkInteractorStyle to add more keyboard
functions to the render window interactor. I've copied the style from sibling
subclasses of vtkInteractorStyle and the class compiles correctly. When I try to
use the class however, the linker complains about an "undefined reference to
'vtkMyInteractorStyle::New(void)'" If you look at the code in the .cxx file you
will see that the New() function most definitely IS defined! Anyone got any
ideas on this?
cheers
Bruce Lamond



My new class .cxx file (vtkMyInteractorStyle.cxx):
================================================================================

#include "vtkMyInteractorStyle.h"


#include "vtkActor.h"
#include "vtkActor2D.h"
#include "vtkAssemblyNode.h"
#include "vtkAssemblyPath.h"
#include "vtkCallbackCommand.h"
#include "vtkCellPicker.h"
#include "vtkMath.h"
#include "vtkObjectFactory.h"
#include "vtkOldStyleCallbackCommand.h"
#include "vtkOutlineSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkProperty2D.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkTextProperty.h"
#include "vtkPointPicker.h"


vtkMyInteractorStyle* vtkMyInteractorStyle::New() {
  // First try to create the object from the vtkObjectFactory
  vtkObject* ret = vtkObjectFactory::CreateInstance("vtkMyInteractorStyle");
  if(ret)
    {
    return (vtkMyInteractorStyle*)ret;
    }
  // If the factory was unable to create the object, then create it here.
  return new vtkMyInteractorStyle;
}


vtkMyInteractorStyle::vtkMyInteractorStyle() {/* constructor stuff */}

vtkMyInteractorStyle::~vtkMyInteractorStyle() {/* destructor stuff */}

vtkMyInteractorStyle::OnChar() {/*method to be overridden in subclass*/}

vtkMyInteractorStyle::PrintSelf(ostream& os, vtkIndent indent) {
  this->vtkInteractorStyle::PrintSelf(os,indent);
  /* other print stuff */
}
================================================================================


My new class .h file (vtkMyInteractorStyle.h):
================================================================================

#ifndef __vtkMyInteractorStyle_h
#define __vtkMyInteractorStyle_h

#include "vtkmyUnsortedWin32Header.h"
#include "vtkInteractorStyle.h"


class VTK_MY_UNSORTED_EXPORT vtkMyInteractorStyle : public vtkInteractorStyle {
public:
  static vtkMyInteractorStyle* New();
  vtkTypeMacro(vtkMyInteractorStyle, vtkInteractorStyle);
  void PrintSelf(ostream& os, vtkIndent indent);

  virtual void OnChar();

protected:
  vtkMyInteractorStyle();
  ~vtkMyInteractorStyle();

private:
  vtkMyInteractorStyle(const vtkMyInteractorStyle&);  // Not implemented.
  void operator=(const vtkMyInteractorStyle&);  // Not implemented.
};

#endif
================================================================================

The main method to use the class:
================================================================================
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include "vtkCubeSource.h"
#include "vtkPropPicker.h"
#include "vtkCommand.h"
#include "vtkObject.h"
#include "vtkMyInteractorStyle.h"
#include "vtkInteractorStyleTrackballActor.h"

void main(int argc, char* argv[]) {

	vtkRenderer *ren = vtkRenderer::New();
		ren->SetBackground(1, 1, 1);
	vtkRenderWindow *renWin = vtkRenderWindow::New();
		renWin->AddRenderer(ren);
		renWin->SetSize(600, 600);
	vtkCubeSource *cube=vtkCubeSource::New();
		cube->SetXLength(40);
		cube->SetYLength(40);
		cube->SetZLength(40);
	vtkPolyDataMapper *cMapper=vtkPolyDataMapper::New();
		cMapper->SetInput(cube->GetOutput());
	vtkActor *cubeActor=vtkActor::New();
		cubeActor->SetMapper(cMapper);
		cubeActor->GetProperty()->SetOpacity(0.4);
		cubeActor->GetProperty()->SetColor(0.3, 0.8, 0.8);

	vtkMyInteractorStyle* style = new vtkMyInteractorStyle;

	vtkRenderWindowInteractor *iren=vtkRenderWindowInteractor::New();
		iren->SetRenderWindow(renWin);
		iren->SetInteractorStyle(style);

	ren->AddActor(cubeActor);
	renWin->Render();
	iren->Initialize();
	iren->Start();
}

================================================================================



More information about the vtkusers mailing list