Skip to content

Commit

Permalink
Added coverage to f3dquakemdlimporter
Browse files Browse the repository at this point in the history
  • Loading branch information
Youva committed Dec 19, 2024
1 parent 988186a commit a874c3a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 91 deletions.
3 changes: 2 additions & 1 deletion plugins/alembic/module/vtkF3DAlembicReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
#ifndef vtkF3DAlembicReader_h
#define vtkF3DAlembicReader_h

#include <memory>
#include <vtkNew.h>
#include <vtkPolyDataAlgorithm.h>
#include <vtkVersion.h>

#include <memory>

class vtkF3DAlembicReader : public vtkPolyDataAlgorithm
{
public:
Expand Down
4 changes: 3 additions & 1 deletion plugins/native/module/Testing/TestF3DQuakeMDLImporter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ int TestF3DQuakeMDLImporter(int vtkNotUsed(argc), char* argv[])
}
vtkIdType selectedAnimationIndex = 1;
importer->EnableAnimation(selectedAnimationIndex);
return numAnimations == 2 ? EXIT_SUCCESS : EXIT_FAILURE;
std::string animationName = importer->GetAnimationName(2);
importer->UpdateTimeStep(0.0);
return numAnimations == 2 && animationName == "" ? EXIT_SUCCESS : EXIT_FAILURE;
}
105 changes: 22 additions & 83 deletions plugins/native/module/vtkF3DQuakeMDLImporter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class vtkF3DQuakeMDLImporter::vtkInternals
}

//----------------------------------------------------------------------------
vtkSmartPointer<vtkTexture> CreateTexture(const std::vector<unsigned char> buffer, int& offset,
vtkSmartPointer<vtkTexture> CreateTexture(const std::vector<unsigned char>& buffer, int& offset,
int skinWidth, int skinHeight, int nbSkins, int selectedSkinIndex)
{
vtkNew<vtkTexture> texture;
Expand Down Expand Up @@ -129,7 +129,7 @@ class vtkF3DQuakeMDLImporter::vtkInternals
};

//----------------------------------------------------------------------------
void CreateMesh(std::vector<unsigned char> buffer, int offset, mdl_header_t* header)
void CreateMesh(const std::vector<unsigned char>& buffer, int offset, mdl_header_t* header)
{
// Read texture coordinates
struct mdl_texcoord_t
Expand Down Expand Up @@ -170,6 +170,8 @@ class vtkF3DQuakeMDLImporter::vtkInternals
};
std::vector<plugin_frame_pointer> framePtr =
std::vector<plugin_frame_pointer>(header->numFrames);
std::vector<std::vector<int>> frameOffsets =
std::vector<std::vector<int>>();
for (int i = 0; i < header->numFrames; i++)
{
int* type = (int*)(buffer.data() + offset);
Expand All @@ -185,16 +187,15 @@ class vtkF3DQuakeMDLImporter::vtkInternals
{
framePtr[i].type = type;
framePtr[i].nb = (int*)(buffer.data() + 4 + offset);

Check warning on line 189 in plugins/native/module/vtkF3DQuakeMDLImporter.cxx

View check run for this annotation

Codecov / codecov/patch

plugins/native/module/vtkF3DQuakeMDLImporter.cxx#L188-L189

Added lines #L188 - L189 were not covered by tests
// mdl_vertex_t* min = reinterpret_cast<mdl_vertex_t*>(buffer.data() + 8 + offset);
// mdl_vertex_t* max = reinterpret_cast<mdl_vertex_t*>(buffer.data() + 12 + offset);
// float* time = framePtr[i].time = reinterpret_cast<float*>(buffer.data() + 16 + offset);
framePtr[i].frames =
(mdl_simpleframe_t*)(buffer.data() + 16 + 4 * (*framePtr[i].nb) + offset);
offset += 16 + (*framePtr[i].nb) * 4;
// float* time = framePtr[i].time = (float*)(buffer.data() + 16 + offset);
frameOffsets.emplace_back(std::vector<int>());
for (int j = 0; j < *framePtr[i].nb; j++)

Check warning on line 192 in plugins/native/module/vtkF3DQuakeMDLImporter.cxx

View check run for this annotation

Codecov / codecov/patch

plugins/native/module/vtkF3DQuakeMDLImporter.cxx#L191-L192

Added lines #L191 - L192 were not covered by tests
{
offset += 24 + 4 * header->numVertices;
frameOffsets[i].emplace_back(
16 + 4 * (*framePtr[i].nb) + j * 4 * (header->numVertices + 6) + offset);

Check warning on line 195 in plugins/native/module/vtkF3DQuakeMDLImporter.cxx

View check run for this annotation

Codecov / codecov/patch

plugins/native/module/vtkF3DQuakeMDLImporter.cxx#L194-L195

Added lines #L194 - L195 were not covered by tests
}
offset += 16 + (*framePtr[i].nb) * 4;
offset += (24 + 4 * header->numVertices) * (*framePtr[i].nb);

Check warning on line 198 in plugins/native/module/vtkF3DQuakeMDLImporter.cxx

View check run for this annotation

Codecov / codecov/patch

plugins/native/module/vtkF3DQuakeMDLImporter.cxx#L197-L198

Added lines #L197 - L198 were not covered by tests
}
}
// Draw cells
Expand Down Expand Up @@ -246,23 +247,27 @@ class vtkF3DQuakeMDLImporter::vtkInternals
normals->Allocate(header->numTriangles * 3 * 3);

plugin_frame_pointer selectedFrame = framePtr[frameNum];
if (*selectedFrame.type == 0)
int numGroupFrames = *selectedFrame.type == 0 ? 1 : *selectedFrame.nb;
for (int groupFrameNum = 0; groupFrameNum < numGroupFrames; groupFrameNum++)
{
mdl_simpleframe_t* selectedSimpleFrame = numGroupFrames > 1
? (mdl_simpleframe_t*)(buffer.data() + frameOffsets[frameNum][groupFrameNum])
: selectedFrame.frames;
for (int i = 0; i < header->numTriangles; i++)
{
vtkIdType vertexNum[3];
for (int j = 0; j < 3; j++)
{
vertexNum[j] = triangles[i].vertex[j];
double v[3] = { double(selectedFrame.frames->verts[vertexNum[j]].v[0]),
double(selectedFrame.frames->verts[vertexNum[j]].v[1]),
double(selectedFrame.frames->verts[vertexNum[j]].v[2]) };
double v[3] = { double(selectedSimpleFrame->verts[vertexNum[j]].v[0]),
double(selectedSimpleFrame->verts[vertexNum[j]].v[1]),
double(selectedSimpleFrame->verts[vertexNum[j]].v[2]) };
for (int k = 0; k < 3; k++)
{
v[k] = v[k] * header->scale[k] + header->translation[k];
}
vertices->InsertPoint(i * 3 + j, v);
int normalIndex = selectedFrame.frames->verts[vertexNum[j]].normalIndex;
int normalIndex = selectedSimpleFrame->verts[vertexNum[j]].normalIndex;
normals->SetTuple3(i * 3 + j, F3DMDLNormalVectors[normalIndex][0] / 255.0,
F3DMDLNormalVectors[normalIndex][1] / 255.0,
F3DMDLNormalVectors[normalIndex][2] / 255.0);
Expand All @@ -272,9 +277,9 @@ class vtkF3DQuakeMDLImporter::vtkInternals
mesh->SetPoints(vertices);
mesh->SetPolys(cells);
mesh->GetPointData()->SetTCoords(textureCoordinates);
// mesh->GetPointData()->SetNormals(normals);
mesh->GetPointData()->SetNormals(normals);
Mesh.emplace_back(mesh);
std::string meshName = std::string(selectedFrame.frames->name);
std::string meshName = std::string(selectedSimpleFrame->name);
for (std::size_t i = 0; i < meshName.size(); i++)
{
if (meshName[i] >= '0' && meshName[i] <= '9')
Expand All @@ -283,7 +288,7 @@ class vtkF3DQuakeMDLImporter::vtkInternals
break;
}
}
if (frameNum == 0)
if (frameNum == 0 && groupFrameNum == 0)
{
frameName = meshName;
NumberOfAnimations++;
Expand All @@ -298,61 +303,6 @@ class vtkF3DQuakeMDLImporter::vtkInternals
}
GroupAndTimeVal.emplace_back(std::make_pair(frameIndex, 0.0));
}
else
{
for (int groupFrameNum = 0; groupFrameNum < *selectedFrame.nb; groupFrameNum++)
{
for (int i = 0; i < header->numTriangles; i++)
{
vtkIdType vertexNum[3];
for (int j = 0; j < 3; j++)
{
vertexNum[j] = triangles[i].vertex[j];
double v[3] = { double(selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[0]),
double(selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[1]),
double(selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].v[2]) };
for (int k = 0; k < 3; k++)
{
v[k] = v[k] * header->scale[k] + header->translation[k];
}
vertices->InsertPoint(i * 3 + j, v);
int normalIndex = selectedFrame.frames[groupFrameNum].verts[vertexNum[j]].normalIndex;
normals->SetTuple3(i * 3 + j, F3DMDLNormalVectors[normalIndex][0] / 255.0,
F3DMDLNormalVectors[normalIndex][1] / 255.0,
F3DMDLNormalVectors[normalIndex][2] / 255.0);
}
}
vtkNew<vtkPolyData> mesh;
mesh->SetPoints(vertices);
mesh->SetPolys(cells);
mesh->GetPointData()->SetTCoords(textureCoordinates);
mesh->GetPointData()->SetNormals(normals);
Mesh.emplace_back(mesh);
std::string meshName = std::string(selectedFrame.frames[groupFrameNum].name);
for (std::size_t i = 0; i < meshName.size(); i++)
{
if (meshName[i] >= '0' && meshName[i] <= '9')
{
meshName = meshName.substr(0, i - 1);
break;
}
}
if (frameNum == 0)
{
frameName = meshName;
NumberOfAnimations++;
AnimationNames.emplace_back(meshName);
}
else if (meshName != frameName)
{
frameIndex++;
NumberOfAnimations++;
AnimationNames.emplace_back(meshName);
frameName = meshName;
}
GroupAndTimeVal.emplace_back(std::make_pair(frameIndex, 0.0));
}
}
}

// Add interpolated frames
Expand Down Expand Up @@ -595,11 +545,6 @@ std::string vtkF3DQuakeMDLImporter::GetCameraName(vtkIdType vtkNotUsed(camIndex)
return "Camera";
}

//----------------------------------------------------------------------------
void vtkF3DQuakeMDLImporter::SetCamera(vtkIdType vtkNotUsed(camIndex))
{
}

//----------------------------------------------------------------------------
void vtkF3DQuakeMDLImporter::ImportCameras(vtkRenderer* renderer)
{
Expand All @@ -611,9 +556,3 @@ void vtkF3DQuakeMDLImporter::ImportLights(vtkRenderer* renderer)
{
this->Internals->ImportLights(renderer);
}

//----------------------------------------------------------------------------
void vtkF3DQuakeMDLImporter::SetFileName(std::string fileName)
{
this->FileName = fileName;
}
7 changes: 1 addition & 6 deletions plugins/native/module/vtkF3DQuakeMDLImporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class vtkF3DQuakeMDLImporter : public vtkF3DImporter
/**
* Set the file name.
*/
void SetFileName(std::string fileName);
vtkSetMacro(FileName, std::string);

/**
* Update actors at the given time value.
Expand Down Expand Up @@ -63,11 +63,6 @@ class vtkF3DQuakeMDLImporter : public vtkF3DImporter
*/
std::string GetCameraName(vtkIdType camIndex) override;

/**
* Enable a specific camera.
*/
void SetCamera(vtkIdType camIndex) override;

protected:
vtkF3DQuakeMDLImporter();
~vtkF3DQuakeMDLImporter() override = default;
Expand Down

0 comments on commit a874c3a

Please sign in to comment.