Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a set of Cpp examples for the new volumetric extension #400

Merged
merged 13 commits into from
Dec 16, 2024

Conversation

vijaiaeroastro
Copy link
Collaborator

@vijaiaeroastro vijaiaeroastro commented Dec 4, 2024

This PR introduces the following Cpp volumetric examples to the develop branch

Creating implicit shapes
  • Sphere
  • Torus
  • Gyroid
  • Cylinder

Then two additional examples

  • Combine functions
  • Volume from Image stack

These have been build using the unit tests created by @3dJan. I can add more examples based on your suggestions.

  • FillMeshWithGyroid

Copy link

codecov bot commented Dec 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 66.09%. Comparing base (932f2d6) to head (3824e5f).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop     #400   +/-   ##
========================================
  Coverage    66.09%   66.09%           
========================================
  Files          395      395           
  Lines        44642    44642           
========================================
  Hits         29506    29506           
  Misses       15136    15136           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@3dJan 3dJan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The examples do not run on my machine due to the use of r-values in the AddLink method. Or maybe it is a lifetime issue of the shared ptr loosing references to early.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This version crashes at least on windows with msvc. AddLink(...) only works with l-values, an act issue I could not resolve.

cosNode is missing an input.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might work:

int main() {
    Lib3MF::PWrapper wrapper = Lib3MF::CWrapper::loadLibrary();
    auto model = wrapper->CreateModel();

    auto gyroidFunction = model->AddImplicitFunction();
    gyroidFunction->SetDisplayName("Gyroid");

    auto input = gyroidFunction->AddInput("pos", "position", Lib3MF::eImplicitPortType::Vector);
    auto sinNode = gyroidFunction->AddSinNode("sin", Lib3MF::eImplicitNodeConfiguration::VectorToVector, "Sine of Position", "group");
    auto cosNode = gyroidFunction->AddCosNode("cos", Lib3MF::eImplicitNodeConfiguration::VectorToVector, "Cosine of Transformed Position", "group");

    auto dotNode = gyroidFunction->AddDotNode("dot", "Dot Product", "group");
    auto sinInputA = sinNode->GetInputA();
    gyroidFunction->AddLink(input, sinInputA);

    auto cosInputA = cosNode->GetInputA();
    gyroidFunction->AddLink(input, cosInputA);
    auto dotInputA = dotNode->GetInputA();
    auto dotInputB = dotNode->GetInputB();

    auto cosResult = cosNode->GetOutputResult();
    auto sinResult = sinNode->GetOutputResult();
    gyroidFunction->AddLink(cosResult, dotInputB);
    gyroidFunction->AddLink(sinResult, dotInputA);

    auto output = gyroidFunction->AddOutput("shape", "Signed Distance Field", Lib3MF::eImplicitPortType::Scalar);
    auto dotResult = dotNode->GetOutputResult();
    gyroidFunction->AddLink(dotResult, output);

    auto writer = model->QueryWriter("3mf");
    writer->WriteToFile("Gyroid.3mf");

    std::cout << "Saved Gyroid.3mf" << std::endl;
    return 0;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just created a PR to ACT for the fix: PR in ACT

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@3dJan How come the unit tests run then ? They also link to the same library right ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vijaiaeroastro The unit tests don't use the return value directly, but store the return value, a shared_ptr, in a variable. That keeps the shared_ptr alive, otherwise it would currently go out of scope without the suggested fix. The API tries to access the already stored raw pointer and fails. See also my comment in PR in ACT.

@vijaiaeroastro
Copy link
Collaborator Author

@3dJan @gangatp I have removed all the other examples and kept only one from @3dJan. We can introduce more later.

@vijaiaeroastro vijaiaeroastro merged commit 905c367 into develop Dec 16, 2024
42 checks passed
@vijaiaeroastro vijaiaeroastro deleted the vijai/volumetricExamples branch December 16, 2024 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants