Skip to content

Commit

Permalink
Changed some functions in quakemdlimporter
Browse files Browse the repository at this point in the history
Also changed the config and added some tests.
  • Loading branch information
Youva committed Jan 19, 2025
1 parent 3774e4e commit 21bc96a
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 81 deletions.
2 changes: 2 additions & 0 deletions application/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ if(NOT F3D_MACOS_BUNDLE)
f3d_test(NAME TestDefaultConfigFileSTL DATA suzanne.stl CONFIG config_build LONG_TIMEOUT TONE_MAPPING UI)
f3d_test(NAME TestDefaultConfigFileTIFF DATA f3d.tif CONFIG config_build LONG_TIMEOUT TONE_MAPPING UI) # Note: This tests config file order as camera_direction is set in different files
f3d_test(NAME TestDefaultConfigFilePLY DATA suzanneRGBA.ply CONFIG config_build LONG_TIMEOUT TONE_MAPPING UI)
f3d_test(NAME TestDefaultConfigFileQuakeMDL DATA glaunch.mdl CONFIG config_build LONG_TIMEOUT UI)
f3d_test(NAME TestDefaultConfigFileAndCommand DATA suzanne.stl ARGS --up=-Y --camera-direction=-1,0.5,-1 CONFIG config_build LONG_TIMEOUT TONE_MAPPING UI)
f3d_test(NAME TestDefaultConfigTranslucent DATA red_translucent_monkey.gltf CONFIG config_build LONG_TIMEOUT TONE_MAPPING UI)

Expand All @@ -384,6 +385,7 @@ if(NOT F3D_MACOS_BUNDLE)
f3d_test(NAME TestThumbnailConfigFileVTI DATA vase_4comp.vti CONFIG thumbnail_build LONG_TIMEOUT TONE_MAPPING)
f3d_test(NAME TestThumbnailConfigFileSTL DATA suzanne.stl CONFIG thumbnail_build LONG_TIMEOUT TONE_MAPPING)
f3d_test(NAME TestThumbnailConfigFilePLY DATA suzanneRGBA.ply CONFIG thumbnail_build LONG_TIMEOUT TONE_MAPPING)
f3d_test(NAME TestThumbnailConfigFileQuakeMDL DATA glaunch.mdl CONFIG thumbnail_build LONG_TIMEOUT)
endif()

# color texture with opacity needs https://gitlab.kitware.com/vtk/vtk/-/merge_requests/9467
Expand Down
3 changes: 2 additions & 1 deletion plugins/native/configs/config.d/10_native.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
"match": ".*(mdl)",
"options":
{
"up": "+Z"
"up": "+Z",
"animation-index": "-1"
}
}
]
3 changes: 2 additions & 1 deletion plugins/native/configs/thumbnail.d/10_native.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
"match": ".*(mdl)",
"options":
{
"up": "+Z"
"up": "+Z",
"animation-index": "-1"
}
}
]
4 changes: 2 additions & 2 deletions plugins/native/module/Testing/TestF3DQuakeMDLImporter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ int TestF3DQuakeMDLImporter(int vtkNotUsed(argc), char* argv[])
}
vtkIdType selectedAnimationIndex = 1;
importer->EnableAnimation(selectedAnimationIndex);
std::string animationName = importer->GetAnimationName(2);
return numAnimations == 2 && animationName == "" ? EXIT_SUCCESS : EXIT_FAILURE;
std::string animationName = importer->GetAnimationName(0);
return numAnimations == 2 && animationName == "stand" ? EXIT_SUCCESS : EXIT_FAILURE;
}
130 changes: 66 additions & 64 deletions plugins/native/module/vtkF3DQuakeMDLImporter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -299,39 +299,7 @@ class vtkF3DQuakeMDLImporter::vtkInternals
}

// Add interpolated frames
// Linear interpolation between frames in the same animation.
for (std::size_t i = 0; i < this->Mesh.size() - 1; i++)
{
if (this->AnimationIds[i + 1].first != this->AnimationIds[i].first)
{
continue;
}
else
{
vtkNew<vtkPoints> vertices;
vertices->Allocate(header->numTriangles * 3);
for (int j = 0; j < header->numTriangles * 3; j++)
{
double* vertex0 = this->Mesh[i]->GetPoint(j);
double* vertex1 = this->Mesh[i + 1]->GetPoint(j);
double interp[3];
interp[0] = vertex0[0] + 0.5 * (vertex1[0] - vertex0[0]);
interp[1] = vertex0[1] + 0.5 * (vertex1[1] - vertex0[1]);
interp[2] = vertex0[2] + 0.5 * (vertex1[2] - vertex0[2]);
vertices->InsertPoint(j, interp);
}
vtkNew<vtkPolyData> mesh;
mesh->SetPoints(vertices);
mesh->SetPolys(cells);
mesh->GetPointData()->SetTCoords(textureCoordinates);
// Inserts frame between i and i+1
this->Mesh.insert(this->Mesh.begin() + i, mesh);
std::pair<int, float> pair = std::make_pair(this->AnimationIds[i].first,
(this->AnimationIds[i].second + this->AnimationIds[i + 1].second) / 2);
// Increments i to avoid infinite loop
this->AnimationIds.insert(this->AnimationIds.begin() + i++, pair);
}
}
this->InterpolateFrames(header, cells, textureCoordinates);
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -432,10 +400,61 @@ class vtkF3DQuakeMDLImporter::vtkInternals
}

//----------------------------------------------------------------------------
void GetTimeRange(vtkIdType vtkNotUsed(animationIndex), double timeRange[2])
void InterpolateFrames(const mdl_header_t* header, const vtkSmartPointer<vtkCellArray>& cells,
const vtkSmartPointer<vtkFloatArray>& textureCoordinates)
{
// Linear interpolation between frames in the same animation.
std::size_t i = 0;
while (i < this->Mesh.size() - 1)
{
if (this->AnimationIds[i + 1].first != this->AnimationIds[i].first)
{
i++; // Move to next frame.
continue;
}
else
{
vtkNew<vtkPoints> vertices;
vertices->Allocate(header->numTriangles * 3);
for (int j = 0; j < header->numTriangles * 3; j++)
{
double* vertex0 = this->Mesh[i]->GetPoint(j);
double* vertex1 = this->Mesh[i + 1]->GetPoint(j);
double interp[3];
interp[0] = vertex0[0] + 0.5 * (vertex1[0] - vertex0[0]);
interp[1] = vertex0[1] + 0.5 * (vertex1[1] - vertex0[1]);
interp[2] = vertex0[2] + 0.5 * (vertex1[2] - vertex0[2]);
vertices->InsertPoint(j, interp);
}
vtkNew<vtkPolyData> mesh;
mesh->SetPoints(vertices);
mesh->SetPolys(cells);
mesh->GetPointData()->SetTCoords(textureCoordinates);
// Inserts frame between i and i+1
this->Mesh.insert(this->Mesh.begin() + i, mesh);
std::pair<int, float> pair = std::make_pair(this->AnimationIds[i].first,
(this->AnimationIds[i].second + this->AnimationIds[i + 1].second) / 2);
this->AnimationIds.insert(this->AnimationIds.begin() + i, pair);
// Because a frame is added at i+1, the next frame is at i+2
i += 2;
}
}
}

//----------------------------------------------------------------------------
void GetTimeRange(vtkIdType animationIndex, double timeRange[2])
{
// Retrieve time range of all previous animations first, then the selected animation index.
timeRange[0] = 0.0;
timeRange[1] = (1.0 / this->FrameRate) * this->AnimationIds.size();
timeRange[1] = 0.0;
for (int i = 0; i <= animationIndex; i++)
{
int numFrames = std::count_if(this->AnimationIds.begin(), this->AnimationIds.end(),
[i](const std::pair<int, float> pair) { return pair.first == i; });
float duration = numFrames / this->FrameRate;
timeRange[0] = timeRange[1];
timeRange[1] += duration;
}
}

vtkF3DQuakeMDLImporter* Parent;
Expand All @@ -453,9 +472,9 @@ class vtkF3DQuakeMDLImporter::vtkInternals

//----------------------------------------------------------------------------
vtkF3DQuakeMDLImporter::vtkF3DQuakeMDLImporter()
: Internals(new vtkF3DQuakeMDLImporter::vtkInternals(this)){

};
: Internals(new vtkF3DQuakeMDLImporter::vtkInternals(this))
{
}

//----------------------------------------------------------------------------
int vtkF3DQuakeMDLImporter::ImportBegin()
Expand All @@ -469,18 +488,6 @@ void vtkF3DQuakeMDLImporter::ImportActors(vtkRenderer* renderer)
this->Internals->ImportActors(renderer);
}

//----------------------------------------------------------------------------
std::string vtkF3DQuakeMDLImporter::GetOutputsDescription()
{
return this->Internals->Description;
}

//----------------------------------------------------------------------------
void vtkF3DQuakeMDLImporter::UpdateTimeStep(double timeValue)
{
return this->Internals->UpdateTimeStep(timeValue);
}

//----------------------------------------------------------------------------
bool vtkF3DQuakeMDLImporter::UpdateAtTimeValue(double timeValue)
{
Expand All @@ -497,31 +504,32 @@ vtkIdType vtkF3DQuakeMDLImporter::GetNumberOfAnimations()
//----------------------------------------------------------------------------
std::string vtkF3DQuakeMDLImporter::GetAnimationName(vtkIdType animationIndex)
{
if (animationIndex < static_cast<vtkIdType>(this->Internals->AnimationNames.size()))
{
return this->Internals->AnimationNames[animationIndex];
}
else
{
return "";
}
assert(animationIndex < static_cast<vtkIdType>(this->Internals->AnimationNames.size()));
assert(animationIndex >= 0);
return this->Internals->AnimationNames[animationIndex];
}

//----------------------------------------------------------------------------
void vtkF3DQuakeMDLImporter::EnableAnimation(vtkIdType animationIndex)
{
assert(animationIndex < static_cast<vtkIdType>(this->Internals->AnimationNames.size()));
assert(animationIndex >= 0);
this->Internals->EnableAnimation(animationIndex);
}

//----------------------------------------------------------------------------
void vtkF3DQuakeMDLImporter::DisableAnimation(vtkIdType animationIndex)
{
assert(animationIndex < static_cast<vtkIdType>(this->Internals->AnimationNames.size()));
assert(animationIndex >= 0);
this->Internals->DisableAnimation(animationIndex);
}

//----------------------------------------------------------------------------
bool vtkF3DQuakeMDLImporter::IsAnimationEnabled(vtkIdType animationIndex)
{
assert(animationIndex < static_cast<vtkIdType>(this->Internals->AnimationNames.size()));
assert(animationIndex >= 0);
return std::count(this->Internals->ActiveAnimationIds.begin(),
this->Internals->ActiveAnimationIds.end(), animationIndex) > 0;
}
Expand All @@ -535,9 +543,3 @@ bool vtkF3DQuakeMDLImporter::GetTemporalInformation(vtkIdType animationIndex, do
nbTimeSteps = static_cast<int>(this->Internals->ActiveFrames.size());
return true;
}

//----------------------------------------------------------------------------
vtkIdType vtkF3DQuakeMDLImporter::GetNumberOfCameras()
{
return 0;
}
14 changes: 1 addition & 13 deletions plugins/native/module/vtkF3DQuakeMDLImporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class vtkF3DQuakeMDLImporter : public vtkF3DImporter
/**
* Update actors at the given time value.
*/
void UpdateTimeStep(double timeValue) override;
bool UpdateAtTimeValue(double timeValue) override;

/**
Expand All @@ -47,23 +46,12 @@ class vtkF3DQuakeMDLImporter : public vtkF3DImporter
bool IsAnimationEnabled(vtkIdType animationIndex) override;
///@}

/**
* Return importer description.
*/
std::string GetOutputsDescription() override;

/**
* Get temporal information for the currently enabled animation.
*/
bool GetTemporalInformation(vtkIdType animationIndex, double frameRate, int& nbTimeSteps,
double timeRange[2], vtkDoubleArray* timeSteps) override;

/**
* Get the number of available cameras.
* Not implemented, multiple cameras are not specified.
*/
vtkIdType GetNumberOfCameras() override;


protected:
vtkF3DQuakeMDLImporter();
~vtkF3DQuakeMDLImporter() override = default;
Expand Down
3 changes: 3 additions & 0 deletions testing/baselines/TestDefaultConfigFileQuakeMDL.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions testing/baselines/TestThumbnailConfigFileQuakeMDL.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 21bc96a

Please sign in to comment.