Skip to content

Commit

Permalink
cleanup generic importer
Browse files Browse the repository at this point in the history
  • Loading branch information
mwestphal committed Sep 25, 2024
1 parent e106306 commit ba6eeb7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
34 changes: 10 additions & 24 deletions vtkext/private/module/vtkF3DGenericImporter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "F3DLog.h"

#include <vtkActor.h>
#include <vtkCallbackCommand.h>
#include <vtkEventForwarderCommand.h>
#include <vtkImageData.h>
#include <vtkInformation.h>
#include <vtkMultiBlockDataSet.h>
Expand Down Expand Up @@ -121,29 +121,15 @@ void vtkF3DGenericImporter::ImportActors(vtkRenderer* ren)
{
bool hasGeometry = true;

// Read file and forward progress
vtkNew<vtkEventForwarderCommand> progressForwarder;
progressForwarder->SetTarget(this);
this->Pimpl->Reader->AddObserver(vtkCommand::ProgressEvent, progressForwarder);
bool status = this->Pimpl->PostPro->GetExecutive()->Update();
if (!status || !this->Pimpl->Reader->GetOutputDataObject(0))
{
// Forward progress event
// TODO simpler impl ?
vtkNew<vtkCallbackCommand> progressCallback;
progressCallback->SetClientData(this);
progressCallback->SetCallback(
[](vtkObject*, unsigned long, void* clientData, void* callData)
{
vtkF3DGenericImporter* self = static_cast<vtkF3DGenericImporter*>(clientData);
double progress = *static_cast<double*>(callData);
self->InvokeEvent(vtkCommand::ProgressEvent, &progress);
});

// Read file
this->Pimpl->Reader->AddObserver(vtkCommand::ProgressEvent, progressCallback);
bool status = this->Pimpl->PostPro->GetExecutive()->Update();
this->Pimpl->Reader->RemoveObservers(vtkCommand::ProgressEvent);

if (!status || !this->Pimpl->Reader->GetOutputDataObject(0))
{
F3DLog::Print(F3DLog::Severity::Warning, "A reader failed to update");
hasGeometry = false;
}
F3DLog::Print(F3DLog::Severity::Warning, "A reader failed to update");
hasGeometry = false;
}

if (hasGeometry)
Expand All @@ -159,7 +145,7 @@ void vtkF3DGenericImporter::ImportActors(vtkRenderer* ren)
this->Pimpl->PolyDataMapper->SetInputConnection(this->Pimpl->PostPro->GetOutputPort(0));

// Set geometry actor default properties
// TODO check: color, opacity, emissive factor, normal scale, metallic
// Rely on vtkProperty default for other properties
this->Pimpl->GeometryActor->GetProperty()->SetPointSize(10.0);
this->Pimpl->GeometryActor->GetProperty()->SetLineWidth(1.0);
this->Pimpl->GeometryActor->GetProperty()->SetRoughness(0.3);
Expand Down
12 changes: 6 additions & 6 deletions vtkext/private/module/vtkF3DGenericImporter.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @class vtkF3DGenericImporter
* @brief create a scene from the meta reader
* @brief create a scene for any vtkAlgorithm
*/

#ifndef vtkF3DGenericImporter_h
Expand All @@ -24,7 +24,7 @@ class vtkF3DGenericImporter : public vtkF3DImporter
vtkTypeMacro(vtkF3DGenericImporter, vtkF3DImporter);

/**
* Set the internal reader to generate actors from
* Set the internal reader to recover actors and data from
*/
void SetInternalReader(vtkAlgorithm* reader);

Expand All @@ -44,7 +44,7 @@ class vtkF3DGenericImporter : public vtkF3DImporter
///@}

/**
* Update readers and all pipelines on the specified timestep
* Update internal reader on the specified timestep
*/
bool UpdateAtTimeValue(double timeValue) override;

Expand All @@ -56,7 +56,7 @@ class vtkF3DGenericImporter : public vtkF3DImporter
vtkIdType GetNumberOfAnimations() override;

/**
* Return a dummy name of the first animation if any, empty string otherwise.
* Return "default" for the first animation if any, empty string otherwise.
*/
std::string GetAnimationName(vtkIdType animationIndex) override;

Expand Down Expand Up @@ -90,8 +90,8 @@ class vtkF3DGenericImporter : public vtkF3DImporter
vtkF3DGenericImporter();
~vtkF3DGenericImporter() override = default;

/* Standard ImportActors
* None of the actors are shown by default
/*
* Import surface from the internal reader output as actors
*/
void ImportActors(vtkRenderer*) override;

Expand Down

0 comments on commit ba6eeb7

Please sign in to comment.