[vtkusers] Please help

Naoko Takaya takaya at cv.cs.ritsumei.ac.jp
Fri Aug 4 02:56:50 EDT 2000


Hello,

Firtsy, please excuse my English.
 
I mailed about this quite a while ago, but I haven’t received an answer
yet.
This might be too easy a question but please help me.
 
I managed to draw a graph from an equation but I want to do the followings;
1. Represent this as a volume
 (I’ve tried some by using vtkVolume and vtkVolumeMapper and so on, but it
keeps on getting errors:( )
2. Cut this graph in slices, say where y=1.
 (I’ve tried this too, but when it won’t give me 2D graph)
 
Sorry for my luck of studying. I will appreciate your help very much.
Thank you :)
 
================================
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkConeSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkStructuredPoints.h"
#include "vtkContourFilter.h"
#include "vtkFloatScalars.h"
#include "math.h"
#include "vtkVolumeMapper.h"
#include "vtkVolume.h"
#include "vtkAxes.h"
 
 
main ()
{
  int i, j, k, kOffset, jOffset, offset;
  float x, y, z, s, sp,p,q,r,y1,x1,pai;
 
  pai = 3.14159267;
  
  vtkRenderer *renderer = vtkRenderer::New();
  vtkRenderWindow *renWin = vtkRenderWindow::New();
    renWin->AddRenderer(renderer);
  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
    iren->SetRenderWindow(renWin);
 
  vtkStructuredPoints *vol = vtkStructuredPoints::New();
      vol->SetDimensions(100,100,100);
          vol->SetOrigin(-2.0,-2.0,-2.0);
          sp =5.0/100;
          vol->SetSpacing(sp,sp,sp); 
 
 
  vtkFloatScalars *scalars = vtkFloatScalars::New();
 
  for (k=0; k<100; k++)
  {
          z=-2.0+k*sp;
          kOffset = k * 100 * 100;
          for (j=0; j<100; j++) 
          {
                  y=-2.0+j*sp;
                  jOffset = j * 100;
                  for (i=0; i<100; i++) 
                  {        
                          x=-2.0+i*sp;
                          x1=x*cos(-pai/4)-y*sin(-pai/4);
                          y1=x*sin(-pai/4)+y*cos(-pai/4);
                          p = 255/92;
                          q = 255/2;
                          r = x1+y1+1;
                          s = p*(x1*x1*x1+y1*y1*y1+1.5*z*z*r-3*x1*y1);
 
                          offset = i + jOffset + kOffset;
                          scalars->InsertScalar(offset,s);
                  }
          }
  }
  vol->GetPointData()->SetScalars(scalars);
      scalars->Delete();
  
  vtkContourFilter *contour = vtkContourFilter::New();
      contour->SetInput(vol);
      contour->SetValue(0,0.0);
 
  vtkPolyDataMapper *volMapper = vtkPolyDataMapper::New();
      volMapper->SetInput(contour->GetOutput());
      volMapper->ScalarVisibilityOff();
  
  vtkActor *volActor = vtkActor::New();
      volActor->SetMapper(volMapper);
 
        /* Axes */
        vtkAxes *axes = vtkAxes::New();
        axes -> SetScaleFactor(2);
        axes -> SetOrigin(0,0,0);
        axes -> SetSymmetric(2);
        vtkPolyDataMapper *axesMapper = vtkPolyDataMapper::New();
        axesMapper -> SetInput(axes->GetOutput());
        vtkActor *axesActor = vtkActor::New();
        axesActor -> SetMapper(axesMapper); 
 
  renderer->AddActor(volActor);
  renderer->AddActor(axesActor);
  renderer->SetBackground(1,1,1);
  renWin->SetSize(450,450);
 
  // interact with data
  renWin->Render();
  iren->Start();
 
  // Clean up
  renderer->Delete();
  renWin->Delete();
  iren->Delete();
  vol->Delete();
  scalars->Delete();
  contour->Delete();
  volActor->Delete();
  axes->Delete();
  axesMapper->Delete();
  axesActor->Delete();
}
 
===============================


**********************************************
*     Naoko Takaya from Japan            *
* e-mail: takaya at cv.cs.ritsumei.ac.jp  *
*********************************************

-------------- next part --------------
A non-text attachment was scrubbed...
Name: winmail.dat
Type: application/ms-tnef
Size: 3276 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20000804/56d6847e/attachment.bin>


More information about the vtkusers mailing list