Visualization Toolkit - How to read and render multiple objects?How to use Boost in Visual Studio 2010VTK (visualization toolkit) versus OSG (OpenSceneGraph) , other?How does vtkImageData store multiple components and how to rendering itIn Visualization Toolkit, which types of objects need Update() and Modified() to be called and when?Can't compile because replace function improperly used?vtkWidget position on multiple renderersRendering VTK visualization using OpenCV insteadIncluding C++ Library in Ubuntu/NetbeansVTK - Share geometry in multiple vtkGenericOpenGLRenderWindowVTK Visualizer in a C++ Class Does not Render the Scene
Checking if an integer is a member of an integer list
Does academia have a lazy work culture?
Are there any examples of technologies have been lost over time?
If Trump gets impeached, how long would Pence be president?
Does the Intel 8086 CPU have user mode and kernel mode?
Why is it considered Acid Rain with pH <5.6
The best place for swimming in Arctic Ocean
Are the named pipe created by `mknod` and the FIFO created by `mkfifo` equivalent?
Why isn't there a serious attempt at creating a third mass-appeal party in the US?
How can I say in Russian "they cannot make the tournament attractive by itself"?
Is there a wealth gap in Boston where the median net worth of white households is $247,500 while the median net worth for black families was $8?
Is there an antonym for "spicy" or "hot" regarding food (NOT "seasoned" but "spicy")?
Could the rotation of a black hole cause other planets to rotate?
What do I do with a party that is much stronger than their level?
How to tar a list of directories only if they exist
Finding minimum time for vehicle to reach to its destination
Did the IBM PC use the 8088's NMI line?
Can anyone give a concrete example to illustrate what is an uniform prior?
Why does Canada require mandatory bilingualism in all government posts?
Seaborn style plot of pandas dataframe
Symplectisation as a functor between appropriate categories
Why can't my huge trees be chopped down?
Polyhedra, Polyhedron, Polytopes and Polygon
What is the difference between 1/3, 1/2, and full casters?
Visualization Toolkit - How to read and render multiple objects?
How to use Boost in Visual Studio 2010VTK (visualization toolkit) versus OSG (OpenSceneGraph) , other?How does vtkImageData store multiple components and how to rendering itIn Visualization Toolkit, which types of objects need Update() and Modified() to be called and when?Can't compile because replace function improperly used?vtkWidget position on multiple renderersRendering VTK visualization using OpenCV insteadIncluding C++ Library in Ubuntu/NetbeansVTK - Share geometry in multiple vtkGenericOpenGLRenderWindowVTK Visualizer in a C++ Class Does not Render the Scene
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm trying to read and render multiple files in a directory (when combined they form an object) using vtk. But so far I'm getting the following error:
ERROR: In D:VTKVTK-srcIOXMLvtkXMLReader.cxx, line 283
vtkXMLPolyDataReader (00D1B560): Error opening file D:3d modelsDist.
ERROR: In D:VTKVTK-srcCommonExecutionModelvtkExecutive.cxx, line 782
vtkCompositeDataPipeline (00CC2078): Algorithm
vtkXMLPolyDataReader(00D1B560) returned failure for request: vtkInformation
(00D20688)
Debug: Off
Modified Time: 8721
Reference Count: 1
Registered Events: (none)
Request: REQUEST_DATA
FORWARD_DIRECTION: 0
ALGORITHM_AFTER_FORWARD: 1
FROM_OUTPUT_PORT: 0
So far what I've tried is reading only 1 file instead of multiple files, but I still the error I mentioned above.
Here's the coding I'm working on:
int main(int argc, char *argv[])
std::string directoryName = "D:\3d models\Dist\" ;
vtkSmartPointer<vtkDirectory> directory = vtkSmartPointer<vtkDirectory>::New();
int opened = directory->Open(directoryName.c_str());
if(!opened)
std::cout << "No es posible abrir este directorio!" << std::endl;
return EXIT_FAILURE;
int numberOfFiles = directory->GetNumberOfFiles();
std::cout << "NUmero de archivos: " << numberOfFiles << std::endl;
for (int i = 0; i < numberOfFiles; i++)
std::string fileString = directoryName;
////fileString += "/";
fileString += directory->GetFile(i);
std::string ext = vtksys::SystemTools::GetFilenameLastExtension(fileString);
std::cout << fileString.c_str() << " extension: " << ext << std::endl;
std::string name = vtksys::SystemTools::GetFilenameWithoutLastExtension(fileString);
std::cout << "nombre: " << name << std::endl;
const char*cstr = fileString.c_str();
std::cout << cstr << endl;
vtkSmartPointer<vtkXMLPolyDataReader> reader =
vtkSmartPointer<vtkXMLPolyDataReader>::New();
reader->SetFileName(cstr);
reader->Update();
reader->GetOutput();
vtkSmartPointer<vtkTransform> transform =
vtkSmartPointer<vtkTransform>::New();
transform->Scale(.005, .005, .005);
vtkSmartPointer<vtkTransformFilter> transformFilter =
vtkSmartPointer<vtkTransformFilter>::New();
transformFilter->SetInputConnection(reader->GetOutputPort());
transformFilter->SetTransform(transform);
// Visualizar
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(transformFilter->GetOutputPort());
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetPosition(1.1, .5, .1);
actor->SetMapper(mapper);
vtkSmartPointer<vtkOpenVRRenderer> renderer =
vtkSmartPointer<vtkOpenVRRenderer>::New();
vtkSmartPointer<vtkOpenVRRenderWindow> renderWindow =
vtkSmartPointer<vtkOpenVRRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkOpenVRRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkOpenVRRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
vtkNew<vtkOpenVRCamera> cam;
renderer->SetActiveCamera(cam);
renderer->AddActor(actor);
renderer->SetBackground(.2, .3, .4);
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
What am I missing? I've tried with different type of files but I still haven't been able to read and render anything using this method.
c++ vtk
add a comment |
I'm trying to read and render multiple files in a directory (when combined they form an object) using vtk. But so far I'm getting the following error:
ERROR: In D:VTKVTK-srcIOXMLvtkXMLReader.cxx, line 283
vtkXMLPolyDataReader (00D1B560): Error opening file D:3d modelsDist.
ERROR: In D:VTKVTK-srcCommonExecutionModelvtkExecutive.cxx, line 782
vtkCompositeDataPipeline (00CC2078): Algorithm
vtkXMLPolyDataReader(00D1B560) returned failure for request: vtkInformation
(00D20688)
Debug: Off
Modified Time: 8721
Reference Count: 1
Registered Events: (none)
Request: REQUEST_DATA
FORWARD_DIRECTION: 0
ALGORITHM_AFTER_FORWARD: 1
FROM_OUTPUT_PORT: 0
So far what I've tried is reading only 1 file instead of multiple files, but I still the error I mentioned above.
Here's the coding I'm working on:
int main(int argc, char *argv[])
std::string directoryName = "D:\3d models\Dist\" ;
vtkSmartPointer<vtkDirectory> directory = vtkSmartPointer<vtkDirectory>::New();
int opened = directory->Open(directoryName.c_str());
if(!opened)
std::cout << "No es posible abrir este directorio!" << std::endl;
return EXIT_FAILURE;
int numberOfFiles = directory->GetNumberOfFiles();
std::cout << "NUmero de archivos: " << numberOfFiles << std::endl;
for (int i = 0; i < numberOfFiles; i++)
std::string fileString = directoryName;
////fileString += "/";
fileString += directory->GetFile(i);
std::string ext = vtksys::SystemTools::GetFilenameLastExtension(fileString);
std::cout << fileString.c_str() << " extension: " << ext << std::endl;
std::string name = vtksys::SystemTools::GetFilenameWithoutLastExtension(fileString);
std::cout << "nombre: " << name << std::endl;
const char*cstr = fileString.c_str();
std::cout << cstr << endl;
vtkSmartPointer<vtkXMLPolyDataReader> reader =
vtkSmartPointer<vtkXMLPolyDataReader>::New();
reader->SetFileName(cstr);
reader->Update();
reader->GetOutput();
vtkSmartPointer<vtkTransform> transform =
vtkSmartPointer<vtkTransform>::New();
transform->Scale(.005, .005, .005);
vtkSmartPointer<vtkTransformFilter> transformFilter =
vtkSmartPointer<vtkTransformFilter>::New();
transformFilter->SetInputConnection(reader->GetOutputPort());
transformFilter->SetTransform(transform);
// Visualizar
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(transformFilter->GetOutputPort());
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetPosition(1.1, .5, .1);
actor->SetMapper(mapper);
vtkSmartPointer<vtkOpenVRRenderer> renderer =
vtkSmartPointer<vtkOpenVRRenderer>::New();
vtkSmartPointer<vtkOpenVRRenderWindow> renderWindow =
vtkSmartPointer<vtkOpenVRRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkOpenVRRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkOpenVRRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
vtkNew<vtkOpenVRCamera> cam;
renderer->SetActiveCamera(cam);
renderer->AddActor(actor);
renderer->SetBackground(.2, .3, .4);
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
What am I missing? I've tried with different type of files but I still haven't been able to read and render anything using this method.
c++ vtk
Well done posting a working main function. Please do not forget to post the #include lines too, it's much easier for the people who want to help you.
– L.C.
Mar 27 at 9:09
add a comment |
I'm trying to read and render multiple files in a directory (when combined they form an object) using vtk. But so far I'm getting the following error:
ERROR: In D:VTKVTK-srcIOXMLvtkXMLReader.cxx, line 283
vtkXMLPolyDataReader (00D1B560): Error opening file D:3d modelsDist.
ERROR: In D:VTKVTK-srcCommonExecutionModelvtkExecutive.cxx, line 782
vtkCompositeDataPipeline (00CC2078): Algorithm
vtkXMLPolyDataReader(00D1B560) returned failure for request: vtkInformation
(00D20688)
Debug: Off
Modified Time: 8721
Reference Count: 1
Registered Events: (none)
Request: REQUEST_DATA
FORWARD_DIRECTION: 0
ALGORITHM_AFTER_FORWARD: 1
FROM_OUTPUT_PORT: 0
So far what I've tried is reading only 1 file instead of multiple files, but I still the error I mentioned above.
Here's the coding I'm working on:
int main(int argc, char *argv[])
std::string directoryName = "D:\3d models\Dist\" ;
vtkSmartPointer<vtkDirectory> directory = vtkSmartPointer<vtkDirectory>::New();
int opened = directory->Open(directoryName.c_str());
if(!opened)
std::cout << "No es posible abrir este directorio!" << std::endl;
return EXIT_FAILURE;
int numberOfFiles = directory->GetNumberOfFiles();
std::cout << "NUmero de archivos: " << numberOfFiles << std::endl;
for (int i = 0; i < numberOfFiles; i++)
std::string fileString = directoryName;
////fileString += "/";
fileString += directory->GetFile(i);
std::string ext = vtksys::SystemTools::GetFilenameLastExtension(fileString);
std::cout << fileString.c_str() << " extension: " << ext << std::endl;
std::string name = vtksys::SystemTools::GetFilenameWithoutLastExtension(fileString);
std::cout << "nombre: " << name << std::endl;
const char*cstr = fileString.c_str();
std::cout << cstr << endl;
vtkSmartPointer<vtkXMLPolyDataReader> reader =
vtkSmartPointer<vtkXMLPolyDataReader>::New();
reader->SetFileName(cstr);
reader->Update();
reader->GetOutput();
vtkSmartPointer<vtkTransform> transform =
vtkSmartPointer<vtkTransform>::New();
transform->Scale(.005, .005, .005);
vtkSmartPointer<vtkTransformFilter> transformFilter =
vtkSmartPointer<vtkTransformFilter>::New();
transformFilter->SetInputConnection(reader->GetOutputPort());
transformFilter->SetTransform(transform);
// Visualizar
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(transformFilter->GetOutputPort());
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetPosition(1.1, .5, .1);
actor->SetMapper(mapper);
vtkSmartPointer<vtkOpenVRRenderer> renderer =
vtkSmartPointer<vtkOpenVRRenderer>::New();
vtkSmartPointer<vtkOpenVRRenderWindow> renderWindow =
vtkSmartPointer<vtkOpenVRRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkOpenVRRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkOpenVRRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
vtkNew<vtkOpenVRCamera> cam;
renderer->SetActiveCamera(cam);
renderer->AddActor(actor);
renderer->SetBackground(.2, .3, .4);
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
What am I missing? I've tried with different type of files but I still haven't been able to read and render anything using this method.
c++ vtk
I'm trying to read and render multiple files in a directory (when combined they form an object) using vtk. But so far I'm getting the following error:
ERROR: In D:VTKVTK-srcIOXMLvtkXMLReader.cxx, line 283
vtkXMLPolyDataReader (00D1B560): Error opening file D:3d modelsDist.
ERROR: In D:VTKVTK-srcCommonExecutionModelvtkExecutive.cxx, line 782
vtkCompositeDataPipeline (00CC2078): Algorithm
vtkXMLPolyDataReader(00D1B560) returned failure for request: vtkInformation
(00D20688)
Debug: Off
Modified Time: 8721
Reference Count: 1
Registered Events: (none)
Request: REQUEST_DATA
FORWARD_DIRECTION: 0
ALGORITHM_AFTER_FORWARD: 1
FROM_OUTPUT_PORT: 0
So far what I've tried is reading only 1 file instead of multiple files, but I still the error I mentioned above.
Here's the coding I'm working on:
int main(int argc, char *argv[])
std::string directoryName = "D:\3d models\Dist\" ;
vtkSmartPointer<vtkDirectory> directory = vtkSmartPointer<vtkDirectory>::New();
int opened = directory->Open(directoryName.c_str());
if(!opened)
std::cout << "No es posible abrir este directorio!" << std::endl;
return EXIT_FAILURE;
int numberOfFiles = directory->GetNumberOfFiles();
std::cout << "NUmero de archivos: " << numberOfFiles << std::endl;
for (int i = 0; i < numberOfFiles; i++)
std::string fileString = directoryName;
////fileString += "/";
fileString += directory->GetFile(i);
std::string ext = vtksys::SystemTools::GetFilenameLastExtension(fileString);
std::cout << fileString.c_str() << " extension: " << ext << std::endl;
std::string name = vtksys::SystemTools::GetFilenameWithoutLastExtension(fileString);
std::cout << "nombre: " << name << std::endl;
const char*cstr = fileString.c_str();
std::cout << cstr << endl;
vtkSmartPointer<vtkXMLPolyDataReader> reader =
vtkSmartPointer<vtkXMLPolyDataReader>::New();
reader->SetFileName(cstr);
reader->Update();
reader->GetOutput();
vtkSmartPointer<vtkTransform> transform =
vtkSmartPointer<vtkTransform>::New();
transform->Scale(.005, .005, .005);
vtkSmartPointer<vtkTransformFilter> transformFilter =
vtkSmartPointer<vtkTransformFilter>::New();
transformFilter->SetInputConnection(reader->GetOutputPort());
transformFilter->SetTransform(transform);
// Visualizar
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(transformFilter->GetOutputPort());
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetPosition(1.1, .5, .1);
actor->SetMapper(mapper);
vtkSmartPointer<vtkOpenVRRenderer> renderer =
vtkSmartPointer<vtkOpenVRRenderer>::New();
vtkSmartPointer<vtkOpenVRRenderWindow> renderWindow =
vtkSmartPointer<vtkOpenVRRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkOpenVRRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkOpenVRRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
vtkNew<vtkOpenVRCamera> cam;
renderer->SetActiveCamera(cam);
renderer->AddActor(actor);
renderer->SetBackground(.2, .3, .4);
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
What am I missing? I've tried with different type of files but I still haven't been able to read and render anything using this method.
c++ vtk
c++ vtk
asked Mar 26 at 18:47
DonKainDonKain
186 bronze badges
186 bronze badges
Well done posting a working main function. Please do not forget to post the #include lines too, it's much easier for the people who want to help you.
– L.C.
Mar 27 at 9:09
add a comment |
Well done posting a working main function. Please do not forget to post the #include lines too, it's much easier for the people who want to help you.
– L.C.
Mar 27 at 9:09
Well done posting a working main function. Please do not forget to post the #include lines too, it's much easier for the people who want to help you.
– L.C.
Mar 27 at 9:09
Well done posting a working main function. Please do not forget to post the #include lines too, it's much easier for the people who want to help you.
– L.C.
Mar 27 at 9:09
add a comment |
1 Answer
1
active
oldest
votes
It looks like the first entry when you list the files in a folder is "." (which is normal), so the path to the file you try to open is "D:3d modelsDist." and it is not a valid file for vtkXMLPolyDataReader.
You should only try to open vtk files written with vtkXMLPolyDataWriter.
For example by checking the extension is ".vtp" (or whatever extension you used to save the files containing your vtkPolyData models).
Check the extension in the first part of your loop:
for (int i = 0; i < numberOfFiles; i++)
{
std::string fileString = directoryName;
////fileString += "/";
fileString += directory->GetFile(i);
std::string ext = vtksys::SystemTools::GetFilenameLastExtension(fileString);
std::cout << fileString.c_str() << " extension: " << ext << std::endl;
// add this line here to skip "." and "..", also fix the extension if not .xml
if (ext.find(".vtp") == std::string::npos) continue;
(...)
I also suspect you are trying to use vtkXMLPolyDataReader while you should use vtkPolyDataReader (this really depends on what writer was used to produce the files). vtkXMLPolyDataReader is the standard reader for .vtp files.
Last, you are creating a renderer, a rendering window and a camera inside the loop: it means one window per object. It's uncommon, is that what you want?
Long story short: you need at least one renderer and one window to display one or many models. Your models are represented by an actor each: the window is where the renderer draws (one or many) actors. A renderer is a rendering pass: of course you can have one rendering pass for each actor, but unless you are sure you need it, you don't.
Here's your code, modified as I would do at your place:
int main(int argc, char *argv[])
std::string directoryName = "D:\3d models\Dist\" ;
vtkSmartPointer<vtkOpenVRRenderer> renderer =
vtkSmartPointer<vtkOpenVRRenderer>::New();
vtkSmartPointer<vtkOpenVRRenderWindow> renderWindow =
vtkSmartPointer<vtkOpenVRRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkOpenVRRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkOpenVRRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
vtkNew<vtkOpenVRCamera> cam;
renderer->SetActiveCamera(cam);
renderer->SetBackground(.2, .3, .4);
vtkSmartPointer<vtkDirectory> directory = vtkSmartPointer<vtkDirectory>::New();
int opened = directory->Open(directoryName.c_str());
if(!opened)
std::cout << "No es posible abrir este directorio!" << std::endl;
return EXIT_FAILURE;
int numberOfFiles = directory->GetNumberOfFiles();
std::cout << "NUmero de archivos: " << numberOfFiles << std::endl;
for (int i = 0; i < numberOfFiles; i++)
std::string fileString = directoryName;
////fileString += "/";
fileString += directory->GetFile(i);
std::string ext = vtksys::SystemTools::GetFilenameLastExtension(fileString);
std::cout << fileString.c_str() << " extension: " << ext << std::endl;
if (ext.find(".vtp") == std::string::npos) continue;
std::string name = vtksys::SystemTools::GetFilenameWithoutLastExtension(fileString);
std::cout << "nombre: " << name << std::endl;
const char*cstr = fileString.c_str();
std::cout << cstr << endl;
vtkSmartPointer<vtkXMLPolyDataReader> reader =
vtkSmartPointer<vtkXMLPolyDataReader>::New();
reader->SetFileName(cstr);
reader->Update();
reader->GetOutput();
vtkSmartPointer<vtkTransform> transform =
vtkSmartPointer<vtkTransform>::New();
transform->Scale(.005, .005, .005);
vtkSmartPointer<vtkTransformFilter> transformFilter =
vtkSmartPointer<vtkTransformFilter>::New();
transformFilter->SetInputConnection(reader->GetOutputPort());
transformFilter->SetTransform(transform);
// Visualizar
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(transformFilter->GetOutputPort());
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetPosition(1.1, .5, .1);
actor->SetMapper(mapper);
renderer->AddActor(actor);
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
Hey L.C, thanks for your reply and for clearing things up. What I want to achieve with this program is to be able to visualize in VR a structure that is made by multiple other small structures (in this case a human organ). After taking a closer look to my code and reading some information online I've realized that indeed I need to create a mapper and a renderer individualy for every single object that I read instead of going with the for loop with just replaces the objects as it reads them.
– DonKain
Mar 27 at 16:49
I also read online that the XMLPolyDataReader is the one I should be using for .vpt files. Is that the correct way?
– DonKain
Mar 27 at 17:09
You are probably right about the vtkXMLPolyDataReader, if it does not work just try the vtkPolyDataReader. I edited the answer to add a short overview of how windows, renderers and actors work.
– L.C.
Mar 27 at 22:21
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55364293%2fvisualization-toolkit-how-to-read-and-render-multiple-objects%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It looks like the first entry when you list the files in a folder is "." (which is normal), so the path to the file you try to open is "D:3d modelsDist." and it is not a valid file for vtkXMLPolyDataReader.
You should only try to open vtk files written with vtkXMLPolyDataWriter.
For example by checking the extension is ".vtp" (or whatever extension you used to save the files containing your vtkPolyData models).
Check the extension in the first part of your loop:
for (int i = 0; i < numberOfFiles; i++)
{
std::string fileString = directoryName;
////fileString += "/";
fileString += directory->GetFile(i);
std::string ext = vtksys::SystemTools::GetFilenameLastExtension(fileString);
std::cout << fileString.c_str() << " extension: " << ext << std::endl;
// add this line here to skip "." and "..", also fix the extension if not .xml
if (ext.find(".vtp") == std::string::npos) continue;
(...)
I also suspect you are trying to use vtkXMLPolyDataReader while you should use vtkPolyDataReader (this really depends on what writer was used to produce the files). vtkXMLPolyDataReader is the standard reader for .vtp files.
Last, you are creating a renderer, a rendering window and a camera inside the loop: it means one window per object. It's uncommon, is that what you want?
Long story short: you need at least one renderer and one window to display one or many models. Your models are represented by an actor each: the window is where the renderer draws (one or many) actors. A renderer is a rendering pass: of course you can have one rendering pass for each actor, but unless you are sure you need it, you don't.
Here's your code, modified as I would do at your place:
int main(int argc, char *argv[])
std::string directoryName = "D:\3d models\Dist\" ;
vtkSmartPointer<vtkOpenVRRenderer> renderer =
vtkSmartPointer<vtkOpenVRRenderer>::New();
vtkSmartPointer<vtkOpenVRRenderWindow> renderWindow =
vtkSmartPointer<vtkOpenVRRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkOpenVRRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkOpenVRRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
vtkNew<vtkOpenVRCamera> cam;
renderer->SetActiveCamera(cam);
renderer->SetBackground(.2, .3, .4);
vtkSmartPointer<vtkDirectory> directory = vtkSmartPointer<vtkDirectory>::New();
int opened = directory->Open(directoryName.c_str());
if(!opened)
std::cout << "No es posible abrir este directorio!" << std::endl;
return EXIT_FAILURE;
int numberOfFiles = directory->GetNumberOfFiles();
std::cout << "NUmero de archivos: " << numberOfFiles << std::endl;
for (int i = 0; i < numberOfFiles; i++)
std::string fileString = directoryName;
////fileString += "/";
fileString += directory->GetFile(i);
std::string ext = vtksys::SystemTools::GetFilenameLastExtension(fileString);
std::cout << fileString.c_str() << " extension: " << ext << std::endl;
if (ext.find(".vtp") == std::string::npos) continue;
std::string name = vtksys::SystemTools::GetFilenameWithoutLastExtension(fileString);
std::cout << "nombre: " << name << std::endl;
const char*cstr = fileString.c_str();
std::cout << cstr << endl;
vtkSmartPointer<vtkXMLPolyDataReader> reader =
vtkSmartPointer<vtkXMLPolyDataReader>::New();
reader->SetFileName(cstr);
reader->Update();
reader->GetOutput();
vtkSmartPointer<vtkTransform> transform =
vtkSmartPointer<vtkTransform>::New();
transform->Scale(.005, .005, .005);
vtkSmartPointer<vtkTransformFilter> transformFilter =
vtkSmartPointer<vtkTransformFilter>::New();
transformFilter->SetInputConnection(reader->GetOutputPort());
transformFilter->SetTransform(transform);
// Visualizar
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(transformFilter->GetOutputPort());
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetPosition(1.1, .5, .1);
actor->SetMapper(mapper);
renderer->AddActor(actor);
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
Hey L.C, thanks for your reply and for clearing things up. What I want to achieve with this program is to be able to visualize in VR a structure that is made by multiple other small structures (in this case a human organ). After taking a closer look to my code and reading some information online I've realized that indeed I need to create a mapper and a renderer individualy for every single object that I read instead of going with the for loop with just replaces the objects as it reads them.
– DonKain
Mar 27 at 16:49
I also read online that the XMLPolyDataReader is the one I should be using for .vpt files. Is that the correct way?
– DonKain
Mar 27 at 17:09
You are probably right about the vtkXMLPolyDataReader, if it does not work just try the vtkPolyDataReader. I edited the answer to add a short overview of how windows, renderers and actors work.
– L.C.
Mar 27 at 22:21
add a comment |
It looks like the first entry when you list the files in a folder is "." (which is normal), so the path to the file you try to open is "D:3d modelsDist." and it is not a valid file for vtkXMLPolyDataReader.
You should only try to open vtk files written with vtkXMLPolyDataWriter.
For example by checking the extension is ".vtp" (or whatever extension you used to save the files containing your vtkPolyData models).
Check the extension in the first part of your loop:
for (int i = 0; i < numberOfFiles; i++)
{
std::string fileString = directoryName;
////fileString += "/";
fileString += directory->GetFile(i);
std::string ext = vtksys::SystemTools::GetFilenameLastExtension(fileString);
std::cout << fileString.c_str() << " extension: " << ext << std::endl;
// add this line here to skip "." and "..", also fix the extension if not .xml
if (ext.find(".vtp") == std::string::npos) continue;
(...)
I also suspect you are trying to use vtkXMLPolyDataReader while you should use vtkPolyDataReader (this really depends on what writer was used to produce the files). vtkXMLPolyDataReader is the standard reader for .vtp files.
Last, you are creating a renderer, a rendering window and a camera inside the loop: it means one window per object. It's uncommon, is that what you want?
Long story short: you need at least one renderer and one window to display one or many models. Your models are represented by an actor each: the window is where the renderer draws (one or many) actors. A renderer is a rendering pass: of course you can have one rendering pass for each actor, but unless you are sure you need it, you don't.
Here's your code, modified as I would do at your place:
int main(int argc, char *argv[])
std::string directoryName = "D:\3d models\Dist\" ;
vtkSmartPointer<vtkOpenVRRenderer> renderer =
vtkSmartPointer<vtkOpenVRRenderer>::New();
vtkSmartPointer<vtkOpenVRRenderWindow> renderWindow =
vtkSmartPointer<vtkOpenVRRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkOpenVRRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkOpenVRRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
vtkNew<vtkOpenVRCamera> cam;
renderer->SetActiveCamera(cam);
renderer->SetBackground(.2, .3, .4);
vtkSmartPointer<vtkDirectory> directory = vtkSmartPointer<vtkDirectory>::New();
int opened = directory->Open(directoryName.c_str());
if(!opened)
std::cout << "No es posible abrir este directorio!" << std::endl;
return EXIT_FAILURE;
int numberOfFiles = directory->GetNumberOfFiles();
std::cout << "NUmero de archivos: " << numberOfFiles << std::endl;
for (int i = 0; i < numberOfFiles; i++)
std::string fileString = directoryName;
////fileString += "/";
fileString += directory->GetFile(i);
std::string ext = vtksys::SystemTools::GetFilenameLastExtension(fileString);
std::cout << fileString.c_str() << " extension: " << ext << std::endl;
if (ext.find(".vtp") == std::string::npos) continue;
std::string name = vtksys::SystemTools::GetFilenameWithoutLastExtension(fileString);
std::cout << "nombre: " << name << std::endl;
const char*cstr = fileString.c_str();
std::cout << cstr << endl;
vtkSmartPointer<vtkXMLPolyDataReader> reader =
vtkSmartPointer<vtkXMLPolyDataReader>::New();
reader->SetFileName(cstr);
reader->Update();
reader->GetOutput();
vtkSmartPointer<vtkTransform> transform =
vtkSmartPointer<vtkTransform>::New();
transform->Scale(.005, .005, .005);
vtkSmartPointer<vtkTransformFilter> transformFilter =
vtkSmartPointer<vtkTransformFilter>::New();
transformFilter->SetInputConnection(reader->GetOutputPort());
transformFilter->SetTransform(transform);
// Visualizar
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(transformFilter->GetOutputPort());
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetPosition(1.1, .5, .1);
actor->SetMapper(mapper);
renderer->AddActor(actor);
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
Hey L.C, thanks for your reply and for clearing things up. What I want to achieve with this program is to be able to visualize in VR a structure that is made by multiple other small structures (in this case a human organ). After taking a closer look to my code and reading some information online I've realized that indeed I need to create a mapper and a renderer individualy for every single object that I read instead of going with the for loop with just replaces the objects as it reads them.
– DonKain
Mar 27 at 16:49
I also read online that the XMLPolyDataReader is the one I should be using for .vpt files. Is that the correct way?
– DonKain
Mar 27 at 17:09
You are probably right about the vtkXMLPolyDataReader, if it does not work just try the vtkPolyDataReader. I edited the answer to add a short overview of how windows, renderers and actors work.
– L.C.
Mar 27 at 22:21
add a comment |
It looks like the first entry when you list the files in a folder is "." (which is normal), so the path to the file you try to open is "D:3d modelsDist." and it is not a valid file for vtkXMLPolyDataReader.
You should only try to open vtk files written with vtkXMLPolyDataWriter.
For example by checking the extension is ".vtp" (or whatever extension you used to save the files containing your vtkPolyData models).
Check the extension in the first part of your loop:
for (int i = 0; i < numberOfFiles; i++)
{
std::string fileString = directoryName;
////fileString += "/";
fileString += directory->GetFile(i);
std::string ext = vtksys::SystemTools::GetFilenameLastExtension(fileString);
std::cout << fileString.c_str() << " extension: " << ext << std::endl;
// add this line here to skip "." and "..", also fix the extension if not .xml
if (ext.find(".vtp") == std::string::npos) continue;
(...)
I also suspect you are trying to use vtkXMLPolyDataReader while you should use vtkPolyDataReader (this really depends on what writer was used to produce the files). vtkXMLPolyDataReader is the standard reader for .vtp files.
Last, you are creating a renderer, a rendering window and a camera inside the loop: it means one window per object. It's uncommon, is that what you want?
Long story short: you need at least one renderer and one window to display one or many models. Your models are represented by an actor each: the window is where the renderer draws (one or many) actors. A renderer is a rendering pass: of course you can have one rendering pass for each actor, but unless you are sure you need it, you don't.
Here's your code, modified as I would do at your place:
int main(int argc, char *argv[])
std::string directoryName = "D:\3d models\Dist\" ;
vtkSmartPointer<vtkOpenVRRenderer> renderer =
vtkSmartPointer<vtkOpenVRRenderer>::New();
vtkSmartPointer<vtkOpenVRRenderWindow> renderWindow =
vtkSmartPointer<vtkOpenVRRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkOpenVRRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkOpenVRRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
vtkNew<vtkOpenVRCamera> cam;
renderer->SetActiveCamera(cam);
renderer->SetBackground(.2, .3, .4);
vtkSmartPointer<vtkDirectory> directory = vtkSmartPointer<vtkDirectory>::New();
int opened = directory->Open(directoryName.c_str());
if(!opened)
std::cout << "No es posible abrir este directorio!" << std::endl;
return EXIT_FAILURE;
int numberOfFiles = directory->GetNumberOfFiles();
std::cout << "NUmero de archivos: " << numberOfFiles << std::endl;
for (int i = 0; i < numberOfFiles; i++)
std::string fileString = directoryName;
////fileString += "/";
fileString += directory->GetFile(i);
std::string ext = vtksys::SystemTools::GetFilenameLastExtension(fileString);
std::cout << fileString.c_str() << " extension: " << ext << std::endl;
if (ext.find(".vtp") == std::string::npos) continue;
std::string name = vtksys::SystemTools::GetFilenameWithoutLastExtension(fileString);
std::cout << "nombre: " << name << std::endl;
const char*cstr = fileString.c_str();
std::cout << cstr << endl;
vtkSmartPointer<vtkXMLPolyDataReader> reader =
vtkSmartPointer<vtkXMLPolyDataReader>::New();
reader->SetFileName(cstr);
reader->Update();
reader->GetOutput();
vtkSmartPointer<vtkTransform> transform =
vtkSmartPointer<vtkTransform>::New();
transform->Scale(.005, .005, .005);
vtkSmartPointer<vtkTransformFilter> transformFilter =
vtkSmartPointer<vtkTransformFilter>::New();
transformFilter->SetInputConnection(reader->GetOutputPort());
transformFilter->SetTransform(transform);
// Visualizar
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(transformFilter->GetOutputPort());
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetPosition(1.1, .5, .1);
actor->SetMapper(mapper);
renderer->AddActor(actor);
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
It looks like the first entry when you list the files in a folder is "." (which is normal), so the path to the file you try to open is "D:3d modelsDist." and it is not a valid file for vtkXMLPolyDataReader.
You should only try to open vtk files written with vtkXMLPolyDataWriter.
For example by checking the extension is ".vtp" (or whatever extension you used to save the files containing your vtkPolyData models).
Check the extension in the first part of your loop:
for (int i = 0; i < numberOfFiles; i++)
{
std::string fileString = directoryName;
////fileString += "/";
fileString += directory->GetFile(i);
std::string ext = vtksys::SystemTools::GetFilenameLastExtension(fileString);
std::cout << fileString.c_str() << " extension: " << ext << std::endl;
// add this line here to skip "." and "..", also fix the extension if not .xml
if (ext.find(".vtp") == std::string::npos) continue;
(...)
I also suspect you are trying to use vtkXMLPolyDataReader while you should use vtkPolyDataReader (this really depends on what writer was used to produce the files). vtkXMLPolyDataReader is the standard reader for .vtp files.
Last, you are creating a renderer, a rendering window and a camera inside the loop: it means one window per object. It's uncommon, is that what you want?
Long story short: you need at least one renderer and one window to display one or many models. Your models are represented by an actor each: the window is where the renderer draws (one or many) actors. A renderer is a rendering pass: of course you can have one rendering pass for each actor, but unless you are sure you need it, you don't.
Here's your code, modified as I would do at your place:
int main(int argc, char *argv[])
std::string directoryName = "D:\3d models\Dist\" ;
vtkSmartPointer<vtkOpenVRRenderer> renderer =
vtkSmartPointer<vtkOpenVRRenderer>::New();
vtkSmartPointer<vtkOpenVRRenderWindow> renderWindow =
vtkSmartPointer<vtkOpenVRRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkOpenVRRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkOpenVRRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
vtkNew<vtkOpenVRCamera> cam;
renderer->SetActiveCamera(cam);
renderer->SetBackground(.2, .3, .4);
vtkSmartPointer<vtkDirectory> directory = vtkSmartPointer<vtkDirectory>::New();
int opened = directory->Open(directoryName.c_str());
if(!opened)
std::cout << "No es posible abrir este directorio!" << std::endl;
return EXIT_FAILURE;
int numberOfFiles = directory->GetNumberOfFiles();
std::cout << "NUmero de archivos: " << numberOfFiles << std::endl;
for (int i = 0; i < numberOfFiles; i++)
std::string fileString = directoryName;
////fileString += "/";
fileString += directory->GetFile(i);
std::string ext = vtksys::SystemTools::GetFilenameLastExtension(fileString);
std::cout << fileString.c_str() << " extension: " << ext << std::endl;
if (ext.find(".vtp") == std::string::npos) continue;
std::string name = vtksys::SystemTools::GetFilenameWithoutLastExtension(fileString);
std::cout << "nombre: " << name << std::endl;
const char*cstr = fileString.c_str();
std::cout << cstr << endl;
vtkSmartPointer<vtkXMLPolyDataReader> reader =
vtkSmartPointer<vtkXMLPolyDataReader>::New();
reader->SetFileName(cstr);
reader->Update();
reader->GetOutput();
vtkSmartPointer<vtkTransform> transform =
vtkSmartPointer<vtkTransform>::New();
transform->Scale(.005, .005, .005);
vtkSmartPointer<vtkTransformFilter> transformFilter =
vtkSmartPointer<vtkTransformFilter>::New();
transformFilter->SetInputConnection(reader->GetOutputPort());
transformFilter->SetTransform(transform);
// Visualizar
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(transformFilter->GetOutputPort());
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetPosition(1.1, .5, .1);
actor->SetMapper(mapper);
renderer->AddActor(actor);
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
edited Mar 27 at 22:33
answered Mar 27 at 8:14
L.C.L.C.
8328 silver badges18 bronze badges
8328 silver badges18 bronze badges
Hey L.C, thanks for your reply and for clearing things up. What I want to achieve with this program is to be able to visualize in VR a structure that is made by multiple other small structures (in this case a human organ). After taking a closer look to my code and reading some information online I've realized that indeed I need to create a mapper and a renderer individualy for every single object that I read instead of going with the for loop with just replaces the objects as it reads them.
– DonKain
Mar 27 at 16:49
I also read online that the XMLPolyDataReader is the one I should be using for .vpt files. Is that the correct way?
– DonKain
Mar 27 at 17:09
You are probably right about the vtkXMLPolyDataReader, if it does not work just try the vtkPolyDataReader. I edited the answer to add a short overview of how windows, renderers and actors work.
– L.C.
Mar 27 at 22:21
add a comment |
Hey L.C, thanks for your reply and for clearing things up. What I want to achieve with this program is to be able to visualize in VR a structure that is made by multiple other small structures (in this case a human organ). After taking a closer look to my code and reading some information online I've realized that indeed I need to create a mapper and a renderer individualy for every single object that I read instead of going with the for loop with just replaces the objects as it reads them.
– DonKain
Mar 27 at 16:49
I also read online that the XMLPolyDataReader is the one I should be using for .vpt files. Is that the correct way?
– DonKain
Mar 27 at 17:09
You are probably right about the vtkXMLPolyDataReader, if it does not work just try the vtkPolyDataReader. I edited the answer to add a short overview of how windows, renderers and actors work.
– L.C.
Mar 27 at 22:21
Hey L.C, thanks for your reply and for clearing things up. What I want to achieve with this program is to be able to visualize in VR a structure that is made by multiple other small structures (in this case a human organ). After taking a closer look to my code and reading some information online I've realized that indeed I need to create a mapper and a renderer individualy for every single object that I read instead of going with the for loop with just replaces the objects as it reads them.
– DonKain
Mar 27 at 16:49
Hey L.C, thanks for your reply and for clearing things up. What I want to achieve with this program is to be able to visualize in VR a structure that is made by multiple other small structures (in this case a human organ). After taking a closer look to my code and reading some information online I've realized that indeed I need to create a mapper and a renderer individualy for every single object that I read instead of going with the for loop with just replaces the objects as it reads them.
– DonKain
Mar 27 at 16:49
I also read online that the XMLPolyDataReader is the one I should be using for .vpt files. Is that the correct way?
– DonKain
Mar 27 at 17:09
I also read online that the XMLPolyDataReader is the one I should be using for .vpt files. Is that the correct way?
– DonKain
Mar 27 at 17:09
You are probably right about the vtkXMLPolyDataReader, if it does not work just try the vtkPolyDataReader. I edited the answer to add a short overview of how windows, renderers and actors work.
– L.C.
Mar 27 at 22:21
You are probably right about the vtkXMLPolyDataReader, if it does not work just try the vtkPolyDataReader. I edited the answer to add a short overview of how windows, renderers and actors work.
– L.C.
Mar 27 at 22:21
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55364293%2fvisualization-toolkit-how-to-read-and-render-multiple-objects%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Well done posting a working main function. Please do not forget to post the #include lines too, it's much easier for the people who want to help you.
– L.C.
Mar 27 at 9:09