[vtkusers] Please help!
Naoko Takaya
takaya at cv.cs.ritsumei.ac.jp
Sun Aug 27 02:41:25 EDT 2000
To all vtkusers
I've sent this before but it seems the server is not working
properly. Please excuse me if you have received several of this
message.
I'm new to Vtk and have sent this mail a while ago
but hasn't received an answere yet.
I want to visualize the volume using vtkStructuredPoint
but I am unable to do that and want to know what is
wrong with my pgm.
This might be an easy question, but any help will be
appreciated. Thank you in advance.
*****************************************************
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkStructuredPoints.h"
#include "vtkContourFilter.h"
#include "vtkScalars.h"
#include "math.h"
#include "vtkVolumeMapper.h"
#include "vtkVolume.h"
#include "vtkAxes.h"
#include "vtkVolumeRayCastMapper.h"
#include "vtkVolumeRayCastCompositeFunction.h"
#include "vtkVolume.h"
#include "vtkVolumeProperty.h"
#include "vtkPiecewiseFunction.h"
class cMine{
public:
void mLeaf();
void mSphere();
};
/* デカルトの正葉形 */
void cMine::mLeaf()
{
int i, j, k, kOffset, jOffset, offset;
float x, y, z, s,sp,p,q,r,y1,x1,pai;
pai = 3.14159267;
sp =5.0/100;
/* Creat rendering window */
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);
vtkScalars *scalars = vtkScalars::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);
/* Isosurface */
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);
/* Render actors */
renderer->AddActor(volActor);
renderer->AddActor(axesActor);
renderer->SetBackground(1,1,1);
renWin->SetSize(450,450);
renWin->Render();
iren->Start();
/* Clear */
renderer->Delete();
renWin->Delete();
iren->Delete();
vol->Delete();
scalars->Delete();
contour->Delete();
volActor->Delete();
axes->Delete();
axesMapper->Delete();
axesActor->Delete();
}
/* 球 */
void cMine::mSphere()
{
int i, j, k, kOffset, jOffset, offset;
float x, y, z, s,sp,pai;
pai = 3.14159267;
sp = 5.0/100;
/* Creat rendering window */
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);
vtkScalars *scalars = vtkScalars::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;
s = x*x+y*y+z*z-(1*1);
offset = i + jOffset + kOffset;
// if (s<0)
// {
scalars->SetDataTypeToUnsignedShort();
scalars->InsertScalar(offset,s);
// }
}
}
}
vol->GetPointData()->SetScalars(scalars);
/* Volume Rendering */
vtkPiecewiseFunction *oTFun = vtkPiecewiseFunction::New();
oTFun -> AddSegment(1,1,1,0.5);
vtkPiecewiseFunction *cTFun = vtkPiecewiseFunction::New();
cTFun -> AddSegment(1,1,1,0.5);
vtkVolumeProperty *volProp = vtkVolumeProperty::New();
volProp -> SetColor(cTFun);
volProp -> SetScalarOpacity(oTFun);
volProp -> SetInterpolationTypeToLinear();
volProp -> ShadeOn();
vtkVolumeRayCastCompositeFunction *cFunction =
vtkVolumeRayCastCompositeFunction::New();
vtkVolumeRayCastMapper *volMapper =vtkVolumeRayCastMapper::New();
volMapper -> SetInput(vol);
volMapper -> SetVolumeRayCastFunction(cFunction);
vtkVolume *volActor = vtkVolume::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);
/* Render actors */
renderer->AddVolume(volActor);
renderer->AddActor(axesActor);
renderer->SetBackground(1,1,1);
renWin->SetSize(450,450);
renWin->Render();
iren->Start();
/* Clear */
renderer->Delete();
renWin->Delete();
iren->Delete();
vol->Delete();
scalars->Delete();
volActor->Delete();
axes->Delete();
axesMapper->Delete();
axesActor->Delete();
oTFun->Delete();
cTFun->Delete();
volProp->Delete();
}
main ()
{
cMine o1,o2;
int n;
cout<<"Select program: ¥n";
cout<<"1. Leaf¥n2. Sphere : ";
cin>>n;
switch(n)
{
case 1:
o1.mLeaf();
break;
case 2:
o2.mSphere();
break;
}
}
**********************************************
* 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: 4144 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20000827/ca088ed3/attachment.bin>
More information about the vtkusers
mailing list