[vtkusers] Vector arrows form a solid patch. How to rectify??
David Gobbi
david.gobbi at gmail.com
Thu Jan 28 12:34:33 EST 2010
Hi Rakesh,
I've had to deal with this same issue in my own software. A good
solution is to use observers.
Usually, I hook into the Renderer's StartEvent. Inside my
CommandCallback, I check the renderer to see how much I need to scale
the actor in order make it always be the same number of pixels across:
double vtkSurfaceCursor::ComputeScale(const double position[3],
vtkRenderer *renderer)
{
// Find the cursor scale factor such that 1 data unit length
// equals 1 screen pixel at the cursor's distance from the camera.
// Start by computing the height of the window at the cursor position.
double worldHeight = 1.0;
vtkCamera *camera = renderer->GetActiveCamera();
if (camera->GetParallelProjection())
{
worldHeight = 2*camera->GetParallelScale();
}
else
{
double cameraPosition[3];
camera->GetPosition(cameraPosition);
worldHeight = 2*(sqrt(vtkMath::Distance2BetweenPoints(position,
cameraPosition))
* tan(0.5*camera->GetViewAngle()/57.296));
}
// Compare world height to window height.
int windowHeight = renderer->GetSize()[1];
double scale = 1.0;
if (windowHeight > 0)
{
scale = worldHeight/windowHeight;
}
return scale;
}
I hope this is the sort of thing that you were looking for.
- David G
On Thu, Jan 28, 2010 at 9:53 AM, Rakesh Patil <rakeshthp at in.com> wrote:
>
> i guess, the way i explained the problem was not correct.. here it goes,
>
> for a large area, if i draw vecot of actual size, it will be visible as a
> small dot. So i need to scale and make it
> large enough that it is visible properly.. And as i zoom in, and go closer
> to them, they must slowly,
> shrink to their actual size...
>
> As kaarthik said, i think i need to write my own actor . But how to do it,
> am not able to understand..
> can anyone guide me..??
>
> Thanks
> Regards
>
> ---------- Original message ----------
> From:David Doria< daviddoria+vtk at gmail.com >
> Date: 27 Jan 10 19:54:04
> Subject: Re: [vtkusers] Vector arrows form a solid patch. How to rectify??
> To: rakeshthp at in.com
>
> On Wed, Jan 27, 2010 at 8:56 AM, Rakesh Patil wrote:
>> Hello,
>>
>> I dont know mush about wrapping the code. It would be nice if anyone helps
>> me out. Here is my code to display vectors
>>
>> unsigned int num_pts = x.size();
>>
>> vtkPoints *pts = vtkPoints::New();
>> pts->SetNumberOfPoints(num_pts);
>>
>> vtkDoubleArray *vecArr = vtkDoubleArray::New();
>> vecArr->SetNumberOfComponents(3);
>> 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);
>>
>> vtkGlyph2D *glyph = vtkGlyph2D::New();
>> glyph->SetInput(uGrid);
>> glyph->SetColorModeToColorByVector();
>> glyph->OrientOn();
>> glyph->SetScaleFactor(1);
>>
>> vtkGlyphSource2D *glyphSource = vtkGlyphSource2D::New();
>> glyphSource->FilledOff();
>> glyphSource->SetGlyphTypeToArrow();
>>
>> glyph->SetInputConnection(1, glyphSource->GetOutputPort());
>>
>> vtkPolyDataMapper *gMapper = vtkPolyDataMapper::New();
>> gMapper->SetInput( glyph->GetOutput());
>> gMapper->ScalarVisibilityOn();
>> gMapper->SetScalarRange(uGrid->GetScalarRange());
>>
>> vtkActor *gactor = vtkActor::New();< br>> gactor->SetMapper(gMapper);
>>
>> pRenderer->AddActor(gactor);
>>
>> pRenderer->Rese tCamera();
>>
>> Do i need to derive a class from vtkActor and override
>> RenderOpaqueGeometry
>> code..?? If so, then how do i scale the glyphs..?? and which part will
>> this
>> code come into picture. Am not that much expert in C++ but can manage with
>> a
>> guidance.
>>
>> Thanks
>>
>> Regards
>>
>> ---------- Original message ----------
>> From:Karthik Krishnan< karthik.krishnan at kitware.com >
>> Date: 25 Jan 10 17:08:12
>> Subject: Re: [vtkusers] Vector arrows form a solid patch. How to rectify??
>> To: Rakesh Patil
>>
>> You'll have to write your own actor wrapping around your existing code
>> and overriding RenderOpaqueGeometry. Its not hard. See several actors
>> in VTK/Rendering that scale their font size based on the size of the
>> viewport etc. Yo u may have to do something similar scaling your glyphs
>> based on the parallel scale / view angle.
>>
>> On Sat, Jan 23, 2010 at 12:49 PM, Rakesh Patil wrote:
>>> hello,
>>>
>>> When i display a vector plot using vtk, it is shown very small like a
>>> dot.
>>> And when i zoom into it, it gets more visible and big. But, i want it in
>>> such a way, that when i display it, at the initial stage itself, the
>>> vectors
>>> must be big enough that can be seen. And when we zoom into it, then the
>>> arrow size must proportionately become small. I Used setscalefactor for
>>> glyph object and got the arrow size increased.
>>>
>>> But where the data is very dense, there a solid patch is formed due to
>>> which
>>> i cannot make out whats the length of the arrow. So as we zoom in, the
>>> arrow
>>> size must be reduced so that at the denser location, i ca n differentiate
>>> among two vectors. How can i do this..??
>>>
>>> Thanks in advance
>>>
>>> Regards
>>> Rakesh
>>>
>>> Get Yourself a cool, short @in.com Email ID now!
>>> _______________________________________ ________
>>> 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
>>
>> _________________________________
>> Karthik Krishnan
>
> This is only a very partial answer, but you can scale an arrow using
> the vtkTransformFilter like this:
>
> http://www.vtk.org/Wiki/VTK/Examples/TransformFilter
>
> Thanks,
>
> David
> _______________________________________________
> 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
> < /blockquote>
>
> Get Yourself a cool, short @in.com Email ID now!
>
> _______________________________________________
> 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
>
>
More information about the vtkusers
mailing list