[vtkusers] need help about vtkBMPReader
med ali
daalyusmo at yahoo.fr
Thu Jun 9 13:42:15 EDT 2005
hi David,
thanks for this example
this example work for one array but i want do that for many arrays of bmp images
because after i will pass the output to the vtkImageMarchingCubes .
how can i do this without using vtkBMPReader.
regards
dali
/////////////////////////////////////////////////////// the code ///////////////////////////////////////////
vtkBMPReader *bmpreader=vtkBMPReader ::New();
bmpreader->SetFilePrefix (prefix);
bmpreader->SetFileNameSliceOffset(1);
bmpreader->SetFilePattern("%s%d.bmp");
bmpreader->SetDataExtent(0,width, 0,height, 0, 31);
//319 -( width-1, 239 - (height-1), 10 - (no of bitmaps-1)
bmpreader->SetDataSpacing(1,1,interslices);
//marchingcubes
vtkImageMarchingCubes *MC=vtkImageMarchingCubes ::New();
MC->SetInput(bmpreader->GetOutput());
MC->SetValue(0,iso-value);
MC->GetOutput()->Update();
//////////////////////////////// ///////////////////////////////////////////////////////
David Cole <david.cole at kitware.com> a écrit :
Please keep questions/replies on the list in case somebody else has time to respond sooner. (Next time, keep cc'ing vtkusers at vtk.org...)
Here's a small example that builds a vtkImageData from raw r,g,b values and shows it in a render window. It's an adaptation and reduction of VTK/Examples/Tutorial/Step6/Cxx/Cone6.cxx. I've eliminated the cone source/mapper/actor and added a vtkImageData and vtkImageActor.
The important pieces of the puzzle are SetScalarTypeToUnsignedChar and SetNumberOfScalarComponents(3). Then you can fill in the r,g,b values to your liking in a loop after allocating the scalars. If you already have a bitmap allocated and filled in, there's probably a way for you to set that data in as the scalar data here as long as it is laid out properly: r, g, b sequentially for each pixel as shown here. I'll let somebody else who's done that before chime in if you need more help. :-)
//====================<SampleCode>====================
#include "vtkImageActor.h"
#include "vtkImageData.h"
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
int main()
{
vtkImageData *imageData = vtkImageData::New();
imageData->SetScalarTypeToUnsignedChar();
imageData->SetNumberOfScalarComponents(3);
imageData->SetDimensions(16, 16, 1);
imageData->AllocateScalars();
int i = 0;
int j = 0;
unsigned char r = 0;
unsigned char g = 0;
unsigned char b = 0;
unsigned char *data = (unsigned char *) imageData->GetScalarPointer();
for (i= 0; i<16; ++i)
for (j= 0; j<16; ++j)
{
// Checkerboard test pattern with red, green, blue and black quadrants:
if ((j+i) % 2)
{
r= g= b= 0;
if (i>7 && j>7)
{
r= 255;
}
else if (i>7)
{
b= 255;
}
else if (j>7)
{
g= 255;
}
}
else
{
// White on the "other" part of the checkerboard:
r= g= b= 255;
// Grayscale ramp:
//r= g= b= 16*i + j;
}
*data++ = r;
*data++ = g;
*data++ = b;
}
vtkImageActor *imageActor = vtkImageActor::New();
imageActor->SetInput(imageData);
imageActor->InterpolateOff();
vtkRenderer *ren1= vtkRenderer::New();
ren1->AddActor( imageActor );
ren1->SetBackground( 0.1, 0.2, 0.4 );
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer( ren1 );
renWin->SetSize( 300, 300 );
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
vtkInteractorStyleTrackballCamera *style = vtkInteractorStyleTrackballCamera::New();
iren->SetInteractorStyle(style);
iren->Initialize();
iren->Start();
imageActor->Delete();
imageData->Delete();
ren1->Delete();
renWin->Delete();
iren->Delete();
style->Delete();
return 0;
}
//====================</SampleCode>====================
Hope this helps you get a little further,
David
med ali wrote: Hi,
thanks you,
but i 'am begginer in vtk
can you give me a short example that i can begin with .
thanks,
dali
David Cole <david.cole at kitware.com> a écrit :
The output of vtkBMPReader (which is derived from vtkImageAlgorithm) is a vtkImageData. Just construct a vtkImageData directly from your data with the correct dimensions, scalar type and underlying data rather than using vtkBMPReader.
med ali wrote:
Hi all,
i want use vtkBMPReader but not directly on the files
instead of passing the prefix of slices can i pass the array data of pixels to vtkBMPReader
/*
bmp= vtkBMPReader::New();
bmp->SetFilePrefix (prefix);
bmp->SetFileNameSliceOffset(1);
bmp->SetFilePattern("%s%d.bmp");
*/
---------------------------------
Découvrez le nouveau Yahoo! Mail : 1 Go d'espace de stockage pour vos mails, photos et vidéos !
Créez votre Yahoo! Mail
---------------------------------
_______________________________________________This is the private VTK discussion list. Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQFollow this link to subscribe/unsubscribe:http://www.vtk.org/mailman/listinfo/vtkusers
---------------------------------
Découvrez le nouveau Yahoo! Mail : 1 Go d'espace de stockage pour vos mails, photos et vidéos !
Créez votre Yahoo! Mail
---------------------------------
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger
Téléchargez le ici !
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20050609/365d8edf/attachment.htm>
More information about the vtkusers
mailing list