[vtkusers] Again, I am doing something wrong. (Mace.cxx)

Nick Edgington OutOfTurn at Yahoo.com
Tue Jan 22 10:48:25 EST 2002


Thanks:
        Enclosed is the working and some what cleaned up code.
    
        Nick Edgington


#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkSphereSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkConeSource.h"
#include "vtkGlyph3D.h"
#include "vtkRenderWindowInteractor.h"

#include "vtkRegressionTestImage.h"
#include "vtkDebugLeaks.h"
#include "vtkObjectFactory.h"

#include "vtkTransform.h"
#include "vtkMath.h"

#include "vtkUnsignedCharArray.h"
#include "vtkFloatArray.h"
#include "vtkOpenGLActor.h"




class vtkMyActor: public  vtkOpenGLActor{
 // float *fData;
 
 vtkMyActor(){
  //  fData=NULL;
 };
 int m_nIndex;
public:
 SetIndex(int nIndex){
  m_nIndex=nIndex;
  //  fData=GetData(nIndex);
 };
 
 // Description
 // Construct object with scaling on, scaling mode is by scalar value, 
 // scale factor = 1.0, the range is (0,1), orient geometry is on, and
 // orientation is by vector. Clamping and indexing are turned off. No
 // initial sources are defined.
 
 static  vtkMyActor*New();
  
 virtual unsigned long GetMTime  (     ) ;
 
};


unsigned long vtkMyActor::GetMTime  (     ){
 // if(fData){
 // SetPosition (fData[0],-fData[1],-fData[2]);
 Modified  () ;
 // }
 unsigned long time=vtkObject::GetMTime  ()  ;
 return time;
}



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





class vtkMyGlyph3D: public  vtkGlyph3D{
 float *fData;
public:
 vtkMyGlyph3D(){//fData=GetData(1);
 };
 
 // Description
 // Construct object with scaling on, scaling mode is by scalar value, 
 // scale factor = 1.0, the range is (0,1), orient geometry is on, and
 // orientation is by vector. Clamping and indexing are turned off. No
 // initial sources are defined.
 static vtkMyGlyph3D *New();
 void Execute();
 
};


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

 int i;
 vtkDebugLeaks::PromptUserOff();
 vtkFloatArray *scalars ;
 vtkRenderer *renderer = vtkRenderer::New();
 vtkRenderWindow *renWin = vtkRenderWindow::New();
    renWin->AddRenderer(renderer);
 vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
    iren->SetRenderWindow(renWin);
 
 
 vtkSphereSource *sphere = vtkSphereSource::New();
    sphere->SetThetaResolution(4);
 sphere->SetPhiResolution(3);
 
 
 vtkConeSource *cone = vtkConeSource::New();
    cone->SetResolution(6);
 

 
 vtkGlyph3D *glyph = vtkGlyph3D::New();
 glyph->SetInput(sphere->GetOutput());
 glyph->SetSource(cone->GetOutput());
 
 glyph->SetVectorModeToUseNormal();
 glyph->SetScaleModeToScaleByVector();
 glyph->SetScaleFactor(.5);
 glyph->SetColorModeToColorByScalar ();
 glyph-> SetScaleModeToDataScalingOff();
  
 
 vtkDataSet *input = glyph->GetInput();


 vtkPointData * pd = input->GetPointData();

 sphere->Update();
 
 sphere->SetOutput(NULL);
 
 vtkPolyData* output= sphere->GetOutput();
 
 scalars = vtkFloatArray::New();
  
 scalars->InsertTuple1(0, .5);
 scalars->InsertTuple1(1, .5);
 scalars->InsertTuple1(2, 1);
 scalars->InsertTuple1(3, 0);
 scalars->InsertTuple1(4, 1);
 scalars->InsertTuple1(5, 0);

 pd->SetScalars(scalars);
 
 
 
 vtkPolyDataMapper *spikeMapper = vtkPolyDataMapper::New();
 
 
 spikeMapper->SetInput(glyph->GetOutput());
 
 
 
 vtkMyActor *spikeActor[1] ;
 for(i=0;i<1;i++){
  spikeActor[i]= vtkMyActor::New();
  spikeActor[i]->SetMapper(spikeMapper);
  
  spikeActor[i]->SetPosition( 63.0327/(i+1),35.5528/(i+1),35.5528/(i+1));
  
  renderer->AddActor(spikeActor[i]);
  spikeActor[i]-> SetIndex(i+1);
  
 } 
 
 renderer->SetBackground(0,0,0);
 renWin->SetSize(1024,1024);
 
 // interact with data
 // while(1)

 renWin->Render();
 int retVal =0; 
 
 iren-> SetDesiredUpdateRate (.1)  ;
 iren->SetStillUpdateRate (.1 );  
    
 iren->Start();
    
 // Clean up but much is left dirty
 renderer->Delete();
 renWin->Delete();
 iren->Delete();
 sphere->Delete();
    
    
 cone->Delete();
 glyph->Delete();
 spikeMapper->Delete();
 for(i=0;i<1;i++){
  spikeActor[i]->Delete();
 }
    return !retVal;
}


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com




More information about the vtkusers mailing list