-
Notifications
You must be signed in to change notification settings - Fork 93
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
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
beaa92c
Include first set of volumetric examples
vijaiaeroastro 2d59f84
Bump examples to C++ 17
vijaiaeroastro 721f83b
.
vijaiaeroastro 78f1f06
Add example for creating a gyroid surface and a box mesh
3dJan 4c937dc
Fix for classParam
3dJan 8c51ef2
Add example for filling a mesh with a gyroid surface
3dJan d52535e
Refactor gyroid function to correct input linking and add subtraction…
3dJan c370893
Merge pull request #402 from 3MFConsortium/3dJan/ExtendVolumetricExam…
3dJan f273dd6
Merging develop into volumetricExamples
vijaiaeroastro 62422e9
Only retain the FillMeshWithGyroid.cpp example
vijaiaeroastro 75d1932
remove volumetric images as they are not in use anymore
vijaiaeroastro 901e4ad
Remove unnecessary executable entries from cmake
vijaiaeroastro 3824e5f
.
vijaiaeroastro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include "lib3mf_implicit.hpp" | ||
#include <iostream> | ||
|
||
int main() { | ||
Lib3MF::PWrapper wrapper = Lib3MF::CWrapper::loadLibrary(); | ||
auto model = wrapper->CreateModel(); | ||
|
||
auto funcA = model->AddImplicitFunction(); | ||
auto funcB = model->AddImplicitFunction(); | ||
funcA->SetDisplayName("FunctionA"); | ||
funcB->SetDisplayName("FunctionB"); | ||
|
||
auto inputA = funcA->AddInput("x", "Position X", Lib3MF::eImplicitPortType::Scalar); | ||
auto sinNode = funcA->AddSinNode("sinA", Lib3MF::eImplicitNodeConfiguration::ScalarToScalar, "Sine Node", "group"); | ||
funcA->AddLink(inputA, sinNode->GetInputA()); | ||
funcA->AddOutput("outputA", "Output A", Lib3MF::eImplicitPortType::Scalar); | ||
|
||
auto inputB = funcB->AddInput("y", "Position Y", Lib3MF::eImplicitPortType::Scalar); | ||
auto cosNode = funcB->AddCosNode("cosB", Lib3MF::eImplicitNodeConfiguration::ScalarToScalar, "Cosine Node", "group"); | ||
funcB->AddLink(inputB, cosNode->GetInputA()); | ||
funcB->AddOutput("outputB", "Output B", Lib3MF::eImplicitPortType::Scalar); | ||
|
||
auto writer = model->QueryWriter("3mf"); | ||
writer->WriteToFile("CombinedFunctions.3mf"); | ||
|
||
std::cout << "Saved CombinedFunctions.3mf" << std::endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "lib3mf_implicit.hpp" | ||
#include <iostream> | ||
|
||
int main() { | ||
Lib3MF::PWrapper wrapper = Lib3MF::CWrapper::loadLibrary(); | ||
auto model = wrapper->CreateModel(); | ||
|
||
auto newFunction = model->AddImplicitFunction(); | ||
newFunction->SetDisplayName("Cylinder"); | ||
|
||
auto input = newFunction->AddInput("pos", "Position", Lib3MF::eImplicitPortType::Vector); | ||
auto cylinderNode = newFunction->AddLengthNode("cylinderNode", "Length", "group"); | ||
newFunction->AddLink(input, cylinderNode->GetInputA()); | ||
|
||
auto output = newFunction->AddOutput("shape", "Cylinder Shape", Lib3MF::eImplicitPortType::Scalar); | ||
newFunction->AddLink(cylinderNode->GetOutputResult(), output); | ||
|
||
auto writer = model->QueryWriter("3mf"); | ||
writer->WriteToFile("Cylinder.3mf"); | ||
|
||
std::cout << "Saved Cylinder.3mf" << std::endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include "lib3mf_implicit.hpp" | ||
#include <iostream> | ||
|
||
int main() { | ||
Lib3MF::PWrapper wrapper = Lib3MF::CWrapper::loadLibrary(); | ||
auto model = wrapper->CreateModel(); | ||
|
||
auto newFunction = model->AddImplicitFunction(); | ||
newFunction->SetDisplayName("Sphere"); | ||
|
||
auto input = newFunction->AddInput("pos", "position", Lib3MF::eImplicitPortType::Vector); | ||
auto constantNode = newFunction->AddConstantNode("radius", "Sphere Radius", "group"); | ||
constantNode->SetConstant(15.0); | ||
|
||
auto lengthNode = newFunction->AddLengthNode("distance", "Distance to sphere", "group"); | ||
newFunction->AddLink(input, lengthNode->GetInputA()); | ||
|
||
auto subtractNode = newFunction->AddSubtractionNode("offset", Lib3MF::eImplicitNodeConfiguration::ScalarToScalar, "Offset Radius", "group"); | ||
newFunction->AddLink(lengthNode->GetOutputResult(), subtractNode->GetInputA()); | ||
newFunction->AddLink(constantNode->GetOutputValue(), subtractNode->GetInputB()); | ||
|
||
auto output = newFunction->AddOutput("shape", "Signed Distance Field", Lib3MF::eImplicitPortType::Scalar); | ||
newFunction->AddLink(subtractNode->GetOutputResult(), output); | ||
|
||
auto writer = model->QueryWriter("3mf"); | ||
writer->WriteToFile("ImplicitSphere.3mf"); | ||
|
||
std::cout << "Saved ImplicitSphere.3mf" << std::endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include "lib3mf_implicit.hpp" | ||
#include <iostream> | ||
|
||
int main() { | ||
Lib3MF::PWrapper wrapper = Lib3MF::CWrapper::loadLibrary(); | ||
auto model = wrapper->CreateModel(); | ||
|
||
auto torusFunction = model->AddImplicitFunction(); | ||
torusFunction->SetDisplayName("Torus"); | ||
|
||
auto input = torusFunction->AddInput("pos", "Position", Lib3MF::eImplicitPortType::Vector); | ||
auto lengthNode = torusFunction->AddLengthNode("length", "Length", "group"); | ||
torusFunction->AddLink(input, lengthNode->GetInputA()); | ||
|
||
auto radiusNode = torusFunction->AddConstantNode("radius", "Radius", "group"); | ||
radiusNode->SetConstant(10.0); | ||
|
||
auto subtractNode = torusFunction->AddSubtractionNode("subtract", Lib3MF::eImplicitNodeConfiguration::ScalarToScalar, "Subtract Radius", "group"); | ||
torusFunction->AddLink(lengthNode->GetOutputResult(), subtractNode->GetInputA()); | ||
torusFunction->AddLink(radiusNode->GetOutputValue(), subtractNode->GetInputB()); | ||
|
||
auto output = torusFunction->AddOutput("shape", "Torus Shape", Lib3MF::eImplicitPortType::Scalar); | ||
torusFunction->AddLink(subtractNode->GetOutputResult(), output); | ||
|
||
auto writer = model->QueryWriter("3mf"); | ||
writer->WriteToFile("Torus.3mf"); | ||
|
||
std::cout << "Saved Torus.3mf" << std::endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include "lib3mf_implicit.hpp" | ||
#include <iostream> | ||
|
||
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"); | ||
gyroidFunction->AddLink(input, sinNode->GetInputA()); | ||
gyroidFunction->AddLink(cosNode->GetOutputResult(), dotNode->GetInputB()); | ||
gyroidFunction->AddLink(sinNode->GetOutputResult(), dotNode->GetInputA()); | ||
|
||
auto output = gyroidFunction->AddOutput("shape", "Signed Distance Field", Lib3MF::eImplicitPortType::Scalar); | ||
gyroidFunction->AddLink(dotNode->GetOutputResult(), output); | ||
|
||
auto writer = model->QueryWriter("3mf"); | ||
writer->WriteToFile("Gyroid.3mf"); | ||
|
||
std::cout << "Saved Gyroid.3mf" << std::endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include "lib3mf_implicit.hpp" | ||
#include <iostream> | ||
#include <filesystem> | ||
|
||
int main() { | ||
Lib3MF::PWrapper wrapper = Lib3MF::CWrapper::loadLibrary(); | ||
auto model = wrapper->CreateModel(); | ||
|
||
constexpr int layers = 11; | ||
|
||
auto pImageStack = model->AddImageStack(821, 819, layers); | ||
|
||
// Resolve the path to the volumetricImages folder relative to the source file | ||
std::string sVolumeImagesFolder = VOLUME_IMAGES_PATH; | ||
std::filesystem::path sourceDir(sVolumeImagesFolder); | ||
sourceDir = std::filesystem::canonical(sourceDir); | ||
|
||
if (!std::filesystem::exists(sourceDir)) { | ||
std::cerr << "Error: Base folder not found - " << sourceDir << "\n"; | ||
return 1; | ||
} | ||
|
||
for (int i = 0; i < layers; ++i) { | ||
std::string sNumber = "_"; | ||
if (i + 1 < 10) sNumber += "0"; | ||
sNumber += std::to_string(i + 1); | ||
|
||
std::string internalPath = "/volume/layer" + sNumber + ".png"; | ||
std::filesystem::path filePath = sourceDir / ("img" + sNumber + ".png"); | ||
|
||
if (!std::filesystem::exists(filePath)) { | ||
std::cerr << "Error: File not found - " << filePath << "\n"; | ||
return 1; | ||
} | ||
|
||
pImageStack->CreateSheetFromFile(i, internalPath, filePath.string()); | ||
} | ||
|
||
// Set up a function from the image stack | ||
auto funcFromImageStack = model->AddFunctionFromImage3D(pImageStack.get()); | ||
funcFromImageStack->SetDisplayName("Function from Image Stack"); | ||
|
||
// Example of setting tile styles (can be customized) | ||
funcFromImageStack->SetTileStyles( | ||
Lib3MF::eTextureTileStyle::Wrap, | ||
Lib3MF::eTextureTileStyle::Clamp, | ||
Lib3MF::eTextureTileStyle::Mirror); | ||
|
||
auto writer = model->QueryWriter("3mf"); | ||
writer->WriteToFile("ImageStack.3mf"); | ||
|
||
std::cout << "Saved ImageStack.3mf\n"; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might work:
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.