extract explicit mesh with topology information from implicit surfaces with boolean operations, and do surface/volume integrating on them.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

142 lines
4.0 KiB

#include "internal_structs.hpp"
namespace internal
{
// ======================================================================
// Runtime Node
// ======================================================================
runtime_node_t::~runtime_node_t() noexcept
{
if (parent) {
if (parent->left_child == this) {
parent->left_child = nullptr;
} else if (parent->right_child == this) {
parent->right_child = nullptr;
}
}
if (left_child) { left_child->parent = nullptr; }
if (right_child) { right_child->parent = nullptr; }
}
bool runtime_node_t::is_operation_node() const noexcept { return std::holds_alternative<eNodeOperation>(node_data); }
bool runtime_node_t::is_primitive_node() const noexcept { return !is_operation_node(); }
bool runtime_node_t::is_parent_null() const noexcept { return parent == nullptr; }
bool runtime_node_t::is_left_child_null() const noexcept { return left_child == nullptr; }
bool runtime_node_t::is_right_child_null() const noexcept { return right_child == nullptr; }
bool runtime_node_t::set_parent(runtime_node_t* _parent) noexcept
{
if (_parent == nullptr) return false;
if (_parent->is_left_child_null())
_parent->left_child = this;
else if (_parent->is_right_child_null())
_parent->right_child = this;
else
return false;
return true;
}
bool runtime_node_t::remove_parent()
{
if (parent == nullptr) return false;
if (parent->left_child == this) {
parent->left_child = nullptr;
} else if (parent->right_child == this) {
parent->right_child = nullptr;
} else {
throw std::logic_error("Illegal parent which does not have a child pointing to this.");
}
parent = nullptr;
return true;
}
bool runtime_node_t::set_left_child(runtime_node_t* child) noexcept
{
if (child == nullptr) return false;
if (!is_left_child_null() || !child->is_parent_null()) return false;
left_child = child;
child->parent = this;
return true;
}
bool runtime_node_t::set_right_child(runtime_node_t* child) noexcept
{
if (child == nullptr) return false;
if (!is_right_child_null() || !child->is_parent_null()) return false;
right_child = child;
child->parent = this;
return true;
}
bool runtime_node_t::add_child(runtime_node_t* child) noexcept
{
if (child == nullptr) return false;
if (!child->is_parent_null()) return false;
if (is_left_child_null())
left_child = child;
else if (is_right_child_null())
right_child = child;
else
return false;
child->parent = this;
return true;
}
bool runtime_node_t::remove_child(runtime_node_t* child)
{
if (child == nullptr) return false;
if (left_child == child) {
left_child = nullptr;
} else if (right_child == child) {
right_child = nullptr;
} else {
throw std::logic_error("Illegal child which does not have a parent pointing to this.");
}
child->parent = nullptr;
return true;
}
// ======================================================================
// Node
// ======================================================================
node_t::node_t() noexcept
: operation(3),
type(63),
primitive_index(0x00FFFFFF),
parent_index(0xFFFFFFFF),
left_child_index(0xFFFFFFFF),
right_child_index(0xFFFFFFFF)
{
}
eNodeOperation node_t::get_operation() const noexcept { return static_cast<eNodeOperation>(operation); }
void node_t::set_operation(eNodeOperation op) noexcept { operation = static_cast<uint32_t>(op); }
bool node_t::is_primitive_node() const noexcept { return type != 63; }
bool node_t::is_operation_node() const noexcept { return type == 63; }
bool node_t::is_parent_null() const noexcept { return parent_index == 0xFFFFFFFF; }
bool node_t::is_left_child_null() const noexcept { return left_child_index == 0xFFFFFFFF; }
bool node_t::is_right_child_null() const noexcept { return right_child_index == 0xFFFFFFFF; }
} // namespace internal