Skip to content

Commit

Permalink
#95: WIP testing images add file support to load ans save jitter dims…
Browse files Browse the repository at this point in the history
… for tests
  • Loading branch information
tlamonthezie committed Jul 30, 2024
1 parent 9b9c770 commit 0c49842
Show file tree
Hide file tree
Showing 10 changed files with 318 additions and 244 deletions.
2 changes: 1 addition & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"env": {
"defines": ["SRC_DIR=\"~/repositories/vt-tv\"", "BUILD_DIR=\"~/repositories/vt-tv/build\""], // defined in cmakelists for compile time
"defines": ["SRC_DIR=\"~/repositories/vt-tv\"", "BUILD_DIR=\"~/repositories/vt-tv/build\"", "VT_TV_HAS_TESTS"], // defined in cmakelists for compile time
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/../vtk/**" // edit vtk include dirs as needed
Expand Down
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
"typeinfo": "cpp",
"valarray": "cpp",
"variant": "cpp",
"*.ipp": "cpp"
"*.ipp": "cpp",
"*.txx": "cpp",
"*.tpp": "cpp"
}
}
72 changes: 16 additions & 56 deletions src/vt-tv/render/render.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@

namespace vt { namespace tv {

void Render::initJitterDims() {
std::srand(std::time(nullptr));
auto const& allObjects = info_.getAllObjectIDs();
for (auto const& objectID : allObjects) {
std::array<double, 3> jitterDims;
for (uint64_t d = 0; d < 3; d++) {
if (auto f = rank_dims_.find(d); f != rank_dims_.end()) {
jitterDims[d] = ((double)std::rand()/RAND_MAX - 0.5) * object_jitter_;
} else jitterDims[d] = 0;
}
jitter_dims_.insert(std::make_pair(objectID, jitterDims));
}
};

Render::Render(Info in_info)
: info_(in_info) // std:move ?
, n_ranks_(in_info.getNumRanks())
Expand Down Expand Up @@ -94,41 +108,7 @@ Render::Render(Info in_info)
std::srand(std::time(nullptr));
auto const& allObjects = info_.getAllObjectIDs();

jitter_dims_ = {};

#ifndef VT_TV_HAS_TESTS
// Load object jitter from file
if (std::getenv("VT_TV_OBJECT_JITTER_DIMS_FILE") != "") {
// to specify values from file
std::ifstream infile(std::getenv("VT_TV_OBJECT_JITTER_DIMS_FILE"));
int objectId, x, y, z;
while (infile >> objectId >> x >> y >> z)
{
std::array<double, 3> jitterDims = {static_cast<double>(x), static_cast<double>(y), static_cast<double>(z)};
jitter_dims_.insert(std::make_pair(objectId, jitterDims));
}
}
#endif

if (jitter_dims_.empty()) {
for (auto const& objectID : allObjects) {
auto jitterDims = getObjectJitterDims(objectID, object_jitter_, rank_dims_);
jitter_dims_.insert(std::make_pair(objectID, jitterDims));
}

#ifndef VT_TV_HAS_TESTS
// Save object jitter to file
if (std::getenv("VT_TV_OBJECT_JITTER_DIMS_FILE") != "") {
// to specify values from file
std::ofstream outfile(std::getenv("VT_TV_OBJECT_JITTER_DIMS_FILE"));
int objectId, x, y, z;
for (auto const& objectID : allObjects) {
auto jitterDims = jitter_dims_.at(objectID);
outfile << objectId << x << y << z;
}
}
#endif
}
initJitterDims();

object_qoi_range_ = this->computeObjectQoiRange_();
rank_qoi_range_ = this->computeRankQoiRange_();
Expand Down Expand Up @@ -186,34 +166,14 @@ Render::Render(
}

// Initialize jitter
std::srand(std::time(nullptr));
auto const& allObjects = info_.getAllObjectIDs();
for (auto const& objectID : allObjects) {
auto jitterDims = getObjectJitterDims(objectID, object_jitter_, rank_dims_);
jitter_dims_.insert(std::make_pair(objectID, jitterDims));
}
#ifdef VT_TV_TESTS
#endif
initJitterDims();

object_qoi_range_ = this->computeObjectQoiRange_();
rank_qoi_range_ = this->computeRankQoiRange_();
object_volume_max_ = this->computeMaxObjectVolume_();
object_load_max_ = this->info_.getMaxLoad();
};

/**
* \brief Function to initialize object dimensions using some randomness
*/
auto getObjectJitterDims(const ElementIDType &objectID, double object_jitter, std::set<uint64_t> rank_dims_) {
std::array<double, 3> jitterDims;
for (uint64_t d = 0; d < 3; d++) {
if (auto f = rank_dims_.find(d); f != rank_dims_.end()) {
jitterDims[d] = ((double)std::rand()/RAND_MAX - 0.5) * object_jitter;
} else jitterDims[d] = 0;
}
return jitterDims;
};

double Render::computeMaxObjectVolume_() {
double ov_max = this->info_.getMaxVolume();
return ov_max;
Expand Down
22 changes: 22 additions & 0 deletions src/vt-tv/render/render.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
#include <array>
#include <variant>
#include <cmath>
#include <regex>

namespace vt { namespace tv {

Expand Down Expand Up @@ -146,6 +147,11 @@ struct Render {
// Jitter per object
std::unordered_map<ElementIDType, std::array<double, 3>> jitter_dims_;

/**
* \brief Function to initialize object dimensions using some randomness
*/
void initJitterDims();

/**
* \brief Compute maximum value of object volumes.
*
Expand Down Expand Up @@ -298,6 +304,22 @@ struct Render {
);

void generate(uint64_t font_size = 50, uint64_t win_size = 2000);

#ifdef VT_TV_HAS_TESTS
/**
* \brief Function to get internal object jitter dimensions.
*/
const std::unordered_map<ElementIDType, std::array<double, 3>> getJitterDims(){
return jitter_dims_;
}

/**
* \brief Function to set manually the internal object jitter dimensions.
*/
void setJitterDims(std::unordered_map<ElementIDType, std::array<double, 3>> jitter_dims){
jitter_dims_ = jitter_dims;
}
#endif
};

}} /* end namespace vt::tv */
Expand Down
18 changes: 18 additions & 0 deletions tests/config/ccm-example-no-png.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
input:
directory: tests/data/ccm_example
n_ranks: 2

viz:
x_ranks: 2
y_ranks: 1
z_ranks: 1
object_jitter: 0.5
rank_qoi: load
object_qoi: shared_block_id
save_meshes: true
save_pngs: false
force_continuous_object_qoi: true

output:
directory: output/tests/no_png
file_stem: ccm_example
18 changes: 18 additions & 0 deletions tests/config/conf-no-png.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
input:
directory: tests/data/lb_test_data
n_ranks: 4

viz:
x_ranks: 2
y_ranks: 2
z_ranks: 1
object_jitter: 0.5
rank_qoi: load
object_qoi: load
save_meshes: true
save_pngs: false
force_continuous_object_qoi: true

output:
directory: output/tests/no_png
file_stem: default
2 changes: 1 addition & 1 deletion tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ macro(vt_tv_link_target target)
)
target_link_libraries(${target} PRIVATE GTest::gtest_main GTest::gmock_main)
target_link_libraries(${target} PUBLIC ${VT_TV_LIBRARY})
target_compile_definitions(${target} PUBLIC VT_TV_HAS_TEST)
target_compile_definitions(${target} PUBLIC VT_TV_HAS_TESTS)
endmacro()

add_executable(
Expand Down
Loading

0 comments on commit 0c49842

Please sign in to comment.