[vtkusers] Generating U, V vleocity vector plots.. Problem!!

da remywendy at gmail.com
Tue Jan 12 10:39:00 EST 2010


Since it says wrong number of components for vector, try setting the number
of components to 3.

vecArr->SetNumberOfComponents(3);

vecArr->InsertTuple3(i, vel_u(i), vel_v(i), 0);

Maybe that might work?


On Mon, Jan 11, 2010 at 10:34 PM, Rakesh Patil <rakeshthp at in.com> wrote:

> HI there..
>
> I got the following data in hand.. Mesh data is in one file and
> corresponding velocity vectors data in another file.. Mesh file format is as
> follows:
>
> NP NE // First line contains total number of points(NP) and total number of
> elements(NE)
> Lon, Lat, depth // From next line onwards NP number of point coordinate
> values are listed
> ...
> ...
> ...
> ele_no, nd1, nd2, nd3 // Index of node 1, 2 and 3 of triangles elements,
> for NE number of elements;
> ...
> ...
> ...
>
> Velocity vectors file contains data in the following format:
>
> time_in_seconds
> point_no, u, v
> ...
> ...
> ...
> next_time_in_seconds
> point_no, u, v
> ...
> ...
> ...
>
> One timestep contains NP number of UV dataset. Now actually, i want to plot
> vector plot for this data ..
> I have used vtkGlyph3D class to do so,.. But all the arrows are being shown
> in the same direction.. Here goes the code:
>
> unsigned int num_pts = x.size();
>
> vtkPoints *pts = vtkPoints::New();
> pts->SetNumberOfPoints(num_pts);
>
> vtkDoubleArray *vecArr = vtkDoubleArray::New();
> vecArr->SetNumberOfComponents(2);
> vecArr->SetNumberOfTuples(num_pts);
>
> for( unsigned int i=0; i < num_pts; i++)
> {
> pts->InsertPoint(i, x(i), y(i), 0);
> vecArr->InsertTuple2(i, vel_u(i), vel_v(i));
> }
>
> unsigned int num_cells = elem.rows(); // elem is a matrix that contains the
> index of nodes of elements in the mesh
>
> vtkCellArray *cellA = vtlCellArray::New();
> cellA->SetNumberOfCells(num_cells);
>
> for (unsigned int i=0; i < num_cells; i++)
> {
> cellA->InsertNextCell(3);
> cellA->InsertCellPoint( elem(i, 0) );
> cellA->InsertCellPoint( elem(i, 1) );
> cellA->InsertCellPoint( elem(i, 2) );
> }
>
> vtkUnstructuredGrid *uGrid = vtkUnstructuredGrid::New();
> uGrid->Allocate(num_cells, num_cells);
> uGrid->SetCells( VTK_TRIANGLE, cellA);
> uGrid->SetPoints(pts);
> uGrid->GetPointData()->SetVector(vecArr);
>
> vtkArrowSource *arrow = vtkArrowSource::New();
> arrow->SetTipResolution(1);
> arrow->SetTipRadius(0.1);
> arrow->SetTipLength(0.35);
> arrow->SetShaftResolution(0.1);
> arrow->SetShaftRadius(0.03);
>
> vtkGlyph3D *glyph = vtkGlyph3D::New();
> glyph->SetInput(uGrid);
> glyph->SetSource(arrow->GetOutput());
> glyph->SetVectorModeToUseVector();
> glyph->SetColorModeToColorByVector();
> glyph->SetScaleModeToDataScalingOff();
> glyph->OrientOn();
> glyph->SetScaleFactor(0.01);
>
> vtkPolyDataMapper *gMapper = vtkPolyDataMapper::New();
> gMapper->SetInput( glyph->GetOutput());
> gMapper->ScalarVisibilityOn();
> gMapper->SetScalarRange(uGrid->GetScalarRange());
>
> vtkActor *gactor = vtkActor::New();
> gactor->SetMapper(gMapper);
>
> pRenderer->AddActor(gactor);
>
> pRenderer->Rese tCamera();
>
> When I run this code, it shows error saying that wrong number of components
> for setVetor(). What is the data it takes.??
> How do i achieve my goal..??
>
> Thanks in advance
>
> Regards
> Rakesh Patil
>
>
> Dear *vtkusers !* Get Yourself a cool, short *@in.com* Email ID now!<http://mail.in.com/mails/new_reg.php?utm_source=invite&utm_medium=outgoing>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100112/f9087217/attachment.htm>


More information about the vtkusers mailing list