[vtkusers] VTk and STL-Containers from C++
Jérôme
jerome.velut at gmail.com
Fri Jul 3 06:40:13 EDT 2009
Hi,
Attached a main.cxx and a CMakeLists.txt for generating the executable. I
modified your source for this to compile on linux. I think it should work on
Win32 too.
Conclusion is: Actors are displaced.
Regards,
Jerome
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090703/f1542359/attachment.htm>
-------------- next part --------------
#include <map>
#include <ctime>
#include "vtkCylinderSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
/// map containing mappers
std::map<unsigned long, vtkPolyDataMapper *, std::less<unsigned long> >
mapper;
/// iterator for mapper
std::map<unsigned long, vtkPolyDataMapper *, std::less<unsigned long>
>::iterator mapper_pos;
/// map containing actors
std::map<unsigned long, vtkActor *, std::less<unsigned long> > actors;
/// iterator for actors
std::map<unsigned long, vtkActor *, std::less<unsigned long> >::iterator
actors_pos;
///map containing Barrel source
std::map<unsigned long, vtkCylinderSource *, std::less<unsigned long> >
cylinder;
/// iterator for mapper
std::map<unsigned long, vtkCylinderSource *, std::less<unsigned long>
>::iterator cylinder_pos;
void setup(vtkRenderer *renderer)
{
int particle_counter = 0;
for(int particle=0; particle<2; particle++)
{
cylinder[particle_counter]=vtkCylinderSource::New();
cylinder[particle_counter]->SetRadius(0.25);
cylinder[particle_counter]->SetHeight(1.);
double shift=particle+1.;
cylinder[particle_counter]->SetCenter(shift, shift, shift);
// mapper responsible for pushing the geometry into the graphics library
mapper[particle_counter] = vtkPolyDataMapper::New();
mapper[particle_counter]->SetInputConnection(cylinder[particle_counter]->GetOutputPort());
// The actor is a grouping mechanism: besides the geometry (mapper), it
// also has a property, transformation matrix, and/or texture map.
actors[particle_counter] = vtkActor::New();
actors[particle_counter]->SetMapper(mapper[particle_counter]);
renderer->AddActor(actors[particle_counter]);
particle_counter++;
}
}
void manipulate(vtkRenderer *renderer)
{
int particle_counter = 0;
for(int particle=0; particle<2; particle++)
{
actors[particle_counter]->SetPosition(0.2, 0.2, 0.3);
particle_counter++;
}
}
int main()
{
vtkRenderer *ren1 = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren1);
ren1->SetBackground(1.,1.,1.);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
setup(ren1);
time_t t0 = time(NULL);
unsigned tmax = 5;
cerr << "Rendering 1" <<endl;
renWin->Render();
while(static_cast<unsigned>(time(NULL)-t0) < tmax);
cerr << "Manipulating" << endl;
manipulate(ren1);
cerr << "Rendering 2" <<endl;
renWin->Render();
t0 = time(NULL);
while(static_cast<unsigned>(time(NULL)-t0) < tmax);
}
-------------- next part --------------
PROJECT (DebugClaudeG)
### The following are needed to avoid warnings. See CMake doc. ######
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
#####################################################################
INCLUDE (${CMAKE_ROOT}/Modules/FindVTK.cmake)
IF (USE_VTK_FILE)
INCLUDE(${USE_VTK_FILE})
ENDIF (USE_VTK_FILE)
SET (LIBRARY_OUTPUT_PATH ${DebugClaudeG_BINARY_DIR}/Bin CACHE PATH
"Single output directory for building all libraries.")
SET (EXECUTABLE_OUTPUT_PATH ${DebugClaudeG_BINARY_DIR}/Bin CACHE PATH
"Single output directory for building all executables.")
INCLUDE_DIRECTORIES (${LIBRARY_OUTPUT_PATH})
INCLUDE_DIRECTORIES (${EXECUTABLE_OUTPUT_PATH})
MARK_AS_ADVANCED(
LIBRARY_OUTPUT_PATH
EXECUTABLE_OUTPUT_PATH
)
ADD_EXECUTABLE( main main.cxx )
TARGET_LINK_LIBRARIES( main vtkIO vtkRendering )
More information about the vtkusers
mailing list