VTK对象自动隐藏问题
vtk吧
全部回复
仅看楼主
level 6
xumg2007 楼主
RT,在旋转VTK对象的过程中,会自动消失,一会之后又自动出现,求大神指教:这是为什么?怎么样避免?
2013年04月12日 01点04分 1
level 12
怎么会忽隐忽现的~ ?这么诡异??
2013年04月12日 10点04分 2
我不知道是不是我的理解有什么不对的啊,我把代码贴出来,你看看
2013年04月15日 01点04分
level 6
xumg2007 楼主
#include "vtkCamera.h"
#include "vtkCellDataToPointData.h"
#include "vtkCompositeDataPipeline.h"
#include "vtkContourFilter.h"
#include "vtkDebugLeaks.h"
#include "vtkHierarchicalDataSetGeometryFilter.h"
#include "vtkOutlineCornerFilter.h"
#include "vtkHierarchicalPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkFloatArray.h"
#include "vtkCellArray.h"
#include "vtkPointData.h"
#include "vtkPolyDataMapper.h"
#include "vtkIdFilter.h"
#include "vtkBandedPolyDataContourFilter.h"
#include "vtkLabeledDataMapper.h"
#include "vtkActor2D.h" int main(int argc, char* argv[])
{ //# Manually create cells of various types: vertex, polyvertex, line,
//# polyline, triangle, quad, pentagon, and triangle strip.
vtkPoints *pts = vtkPoints::New();
pts->InsertPoint(0 ,0 ,0 ,0 );
pts->InsertPoint(1 ,0 ,1 ,0 );
pts->InsertPoint(2 ,0 ,2 ,0 );
pts->InsertPoint(3 ,1 ,0 ,0 );
pts->InsertPoint(4 ,1 ,1 ,0 );
pts->InsertPoint(5 ,1 ,2 ,0 );
pts->InsertPoint(6 ,2 ,0 ,0 );
pts->InsertPoint(7 ,2 ,2 ,0 );
pts->InsertPoint(8 ,3 ,0 ,0 );
pts->InsertPoint(9 ,3 ,1 ,0 );
pts->InsertPoint(10,3 ,2 ,0 );
pts->InsertPoint(11,4 ,0 ,0 );
pts->InsertPoint(12,6 ,0 ,0 );
pts->InsertPoint(13,5 ,2 ,0 );
pts->InsertPoint(14,7 ,0 ,0 );
pts->InsertPoint(15,9 ,0 ,0 );
pts->InsertPoint(16,7 ,2 ,0 );
pts->InsertPoint(17,9 ,2 ,0 );
pts->InsertPoint(18,10, 0, 0);
pts->InsertPoint(19,12, 0, 0);
pts->InsertPoint(20,10, 1, 0);
pts->InsertPoint(21,12, 1, 0);
pts->InsertPoint(22,10, 2, 0);
pts->InsertPoint(23,12, 2, 0);
pts->InsertPoint(24,10, 3, 0);
pts->InsertPoint(25,12, 3, 0);
pts->InsertPoint(26,14, 0, 0);
pts->InsertPoint(27,14, 2, 0);
pts->InsertPoint(28,16, 2, 0);
pts->InsertPoint(29,16, 0, 0);
pts->InsertPoint(30,14, 0, 2);
pts->InsertPoint(31,14, 2, 2);
pts->InsertPoint(32,16, 2, 2);
pts->InsertPoint(33,16, 0, 2); vtkCellArray *verts = vtkCellArray::New();
verts->InsertNextCell (1 );
verts->InsertCellPoint( 0);
verts->InsertNextCell (1 );
verts->InsertCellPoint( 1);
verts->InsertNextCell (1 );
verts->InsertCellPoint( 2);
verts->InsertNextCell (3 );
verts->InsertCellPoint( 3);
verts->InsertCellPoint( 4);
verts->InsertCellPoint( 5); vtkCellArray *lines = vtkCellArray::New();
lines->InsertNextCell (2 );
lines->InsertCellPoint( 6 );
lines->InsertCellPoint( 7 );
lines->InsertNextCell (3 );
lines->InsertCellPoint( 8 );
lines->InsertCellPoint( 9 );
lines->InsertCellPoint( 10); vtkCellArray *polys = vtkCellArray::New();
polys->InsertNextCell (4 );
polys->InsertCellPoint( 14);
polys->InsertCellPoint( 15);
polys->InsertCellPoint( 17);
polys->InsertCellPoint( 16);
polys->InsertNextCell (3 );
polys->InsertCellPoint( 11);
polys->InsertCellPoint( 12);
polys->InsertCellPoint( 13);
polys->InsertNextCell (4 );
polys->InsertCellPoint( 26);
polys->InsertCellPoint( 27);
polys->InsertCellPoint( 28);
polys->InsertCellPoint( 29);
polys->InsertNextCell (4 );
polys->InsertCellPoint( 30);
polys->InsertCellPoint( 31);
polys->InsertCellPoint( 32);
polys->InsertCellPoint( 33);
polys->InsertNextCell (4 );
polys->InsertCellPoint( 26);
polys->InsertCellPoint( 27);
polys->InsertCellPoint( 31);
polys->InsertCellPoint( 30);
polys->InsertNextCell (4 );
polys->InsertCellPoint( 28);
polys->InsertCellPoint( 29);
polys->InsertCellPoint( 33);
polys->InsertCellPoint( 32);
polys->InsertNextCell (4 );
polys->InsertCellPoint( 27);
polys->InsertCellPoint( 28);
polys->InsertCellPoint( 32);
polys->InsertCellPoint( 31);
polys->InsertNextCell (4 );
polys->InsertCellPoint( 26);
polys->InsertCellPoint( 29);
polys->InsertCellPoint( 33);
polys->InsertCellPoint( 30); vtkCellArray *strips = vtkCellArray::New();
strips->InsertNextCell (8 );
strips->InsertCellPoint( 19);
strips->InsertCellPoint( 18);
strips->InsertCellPoint( 21);
strips->InsertCellPoint( 20);
strips->InsertCellPoint( 23);
strips->InsertCellPoint( 22);
strips->InsertCellPoint( 25);
strips->InsertCellPoint( 24); vtkFloatArray *scalars = vtkFloatArray::New();
scalars->SetNumberOfTuples(33);
scalars->SetTuple1( 0 ,0 );
scalars->SetTuple1( 1 ,50 );
scalars->SetTuple1( 2 ,100 );
scalars->SetTuple1( 3 ,0 );
scalars->SetTuple1( 4 ,50 );
scalars->SetTuple1( 5 ,100 );
scalars->SetTuple1( 6 ,10 );
scalars->SetTuple1( 7 ,90 );
scalars->SetTuple1( 8 ,10 );
scalars->SetTuple1( 9 ,50 );
scalars->SetTuple1( 10, 90 );
scalars->SetTuple1( 11, 10 );
scalars->SetTuple1( 12, 40 );
scalars->SetTuple1( 13, 100);
scalars->SetTuple1( 14, 0 );
scalars->SetTuple1( 15, 60 );
scalars->SetTuple1( 16, 40 );
scalars->SetTuple1( 17, 100);
scalars->SetTuple1( 18, 0 );
scalars->SetTuple1( 19, 25 );
scalars->SetTuple1( 20, 25 );
scalars->SetTuple1( 21, 50 );
scalars->SetTuple1( 22, 50 );
scalars->SetTuple1( 23, 75 );
scalars->SetTuple1( 24, 75 );
scalars->SetTuple1( 25, 100);
scalars->SetTuple1( 26, 0 );
scalars->SetTuple1( 27, 05 );
scalars->SetTuple1( 28, 25 );
scalars->SetTuple1( 29, 50 );
scalars->SetTuple1( 30, 50 );
scalars->SetTuple1( 31, 75 );
scalars->SetTuple1( 32, 75 );
scalars->SetTuple1( 33, 100); vtkPolyData *polyData = vtkPolyData::New();
polyData->SetPoints( pts );
polyData->SetVerts (verts );
polyData->SetLines (lines );
polyData->SetPolys (polys );
polyData->SetStrips( strips);
(polyData->GetPointData())->SetScalars(scalars); vtkBandedPolyDataContourFilter *bf = vtkBandedPolyDataContourFilter::New();
bf->SetInput(polyData);
//bf->GenerateValues(3,25,75 );
//bf->GenerateValues(9,5,95 );
bf->SetNumberOfContours( 9 );
bf->SetValue(0,5);
bf->SetValue(1,15);
bf->SetValue(2,25);
bf->SetValue(3,35);
bf->SetValue(4,45);
bf->SetValue(5,55);
bf->SetValue(6,65);
bf->SetValue(7,75);
bf->SetValue(8,85);
vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
mapper->SetInputConnection(bf->GetOutputPort());
mapper->SetScalarModeToUseCellData();
//mapper->SetScalarRange(0,4);
mapper->SetScalarRange(0,10);
vtkActor *actor = vtkActor::New();
actor->SetMapper(mapper); vtkIdFilter *ids = vtkIdFilter::New();
ids->SetInputConnection(bf->GetOutputPort());
ids->PointIdsOn();
ids->CellIdsOn();
ids->FieldDataOn();
vtkLabeledDataMapper *ldm = vtkLabeledDataMapper::New();
ldm->SetInputConnection(ids->GetOutputPort());
//# ldm SetLabelFormat "%g"
ldm->SetLabelModeToLabelFieldData();
vtkActor2D *pointLabels = vtkActor2D::New();
pointLabels->SetMapper(ldm);
//# Create the RenderWindow, Renderer and both Actors
//#
vtkRenderer *ren1 = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren1);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin); //# Add the actors to the renderer, set the background and size
//#
ren1->AddActor(actor);
ren1->AddActor2D(pointLabels);
//#for debugging only
ren1->SetBackground(0,0,0);
renWin->SetSize(300,80);
renWin->Render();
(ren1->GetActiveCamera())->Zoom(3);
renWin->Render();
iren->Initialize();
iren->Start();
return 0;
}
2013年04月15日 01点04分 4
刚忙完,这就编译帮你看哈,
2013年04月16日 10点04分
level 12
有什么问题吗?你的结果不是这样的?正常吧~
2013年04月16日 10点04分 5
level 12
我猜你是不是按下鼠标滚轮 旋转的?。。。。
2013年04月16日 10点04分 6
鼠标滚轮只能放大缩小啊,不能旋转
2013年04月16日 11点04分
回复 xumg2007 :呵呵,你把鼠标滚轮按下去,不滚动~ 就看见图像飞起来了~~[Love]
2013年04月16日 13点04分
回复 rabbitbride :按住中间键不放那个算是位移吧,能算旋转吗?还有,按住左键不放就会出现下图的现象
2013年04月17日 00点04分
回复 xumg2007 :这个鼠标响应算正常吧?
2013年04月17日 05点04分
level 6
xumg2007 楼主
我把我这边的图也传下
2013年04月16日 11点04分 8
level 2
解决了吗?,最近我也遇到这个问题,我画的网格,网格线随着视角旋转消失又出现
2023年02月17日 01点02分 9
1