This is an example of how to use the netdem library.
#include <filesystem>
#include <iostream>
#include <unordered_map>
using namespace std;
void TestLatentSpace() {
vector<string> template_names;
ifstream file("template_dict.txt");
if (file.is_open()) {
string line;
while (getline(file, line)) {
template_names.push_back(line);
}
file.close();
} else {
cout << "file template_dict.txt not exist" << endl;
return;
}
int num_templates = template_names.size();
arma::mat latent_code;
mlpack::data::Load("latent_code.txt", latent_code, false, false);
int num_latent_code = latent_code.n_cols;
model.
Load(
"ann_SDF.xml",
"SDF");
cout << "finished loading ann model ..." << endl;
VecXT<Vec3d> searching_points = SphericalVoronoi::Solve(1000, 10000, 1.0e-4);
for (int ii = 0; ii < num_templates; ii++) {
int num_intervals = 100;
for (int jj = 0; jj <= num_intervals; jj++) {
double weight = jj * 1.0 / num_intervals;
for (auto vert : searching_points) {
vert = vert * 0.5;
for (int iter = 0; iter < 10; iter++) {
arma::mat test_x_coded(num_latent_code + vert.size(), 1);
for (int i = 0; i < num_latent_code; i++) {
test_x_coded(i, 0) =
latent_code(ii, i) * (1.0 - weight) +
latent_code((ii + 1) % num_templates, i) * weight;
}
for (int i = num_latent_code; i < test_x_coded.n_rows; i++) {
test_x_coded(i, 0) = vert[i - num_latent_code];
}
auto sdf = model.
Predict(test_x_coded);
if (abs(sdf(0, 0)) > 0.001) {
auto dydx = model.
Gradient(test_x_coded);
vert[0] -= sdf(0, 0) * dydx(0, 0 + num_latent_code);
vert[1] -= sdf(0, 0) * dydx(0, 1 + num_latent_code);
vert[2] -= sdf(0, 0) * dydx(0, 2 + num_latent_code);
} else {
break;
}
}
surf_vertices.emplace_back(vert);
}
string root_dir = "shape_netsdf_" + IO::ToString(ii) + "_" +
IO::ToString((ii + 1) % num_templates);
filesystem::create_directory(root_dir);
IO::ToString(ii) + "_" +
IO::ToString((ii + 1) % num_templates) +
"_" + IO::ToString(jj) + ".stl");
}
}
}
A class that represents a feedforward neural network for regression.
Definition regression_net.hpp:21
arma::mat Gradient(const arma::mat &data_x)
Calculates the gradient of the neural network model with respect to input data.
Definition regression_net.cpp:68
void Load(std::string const &filename, std::string const &label)
Loads the neural network model from disk.
Definition regression_net.cpp:95
arma::mat Predict(const arma::mat &data_x)
Predicts with the neural network model using input data.
Definition regression_net.cpp:62
void SaveAsSTL(std::string const &file) const
Save the model as an STL file.
Definition stl_model.cpp:205
A class representing a spherical harmonics object.
Definition shape_spherical_harmonics.hpp:24
STLModel GetSTLModel(int num_nodes=200) override
Generate an STL model for the SphericalHarmonics object.
Definition shape_spherical_harmonics.cpp:184
void InitFromSurfacePoints(VecXT< Vec3d > const surf_points)
Initialize the SphericalHarmonics object from a list of surface points.
Definition shape_spherical_harmonics.cpp:81
Definition bond_entry.hpp:7
std::vector< T > VecXT
Definition utils_macros.hpp:31