Celeritas  0.5.0-56+6b053cd
Functions
CsgTreeUtils.hh File Reference

Free functions to apply to a CSG tree. More...

#include <vector>
#include "orange/OrangeTypes.hh"
#include "CsgTypes.hh"
This graph shows which files directly or indirectly include this file:

Functions

std::vector< NodeId > celeritas::orangeinp::replace_and_simplify (CsgTree *tree, NodeId repl_key, Node repl_value)
 Replace the given node ID with the replacement node. More...
 
NodeId celeritas::orangeinp::simplify_up (CsgTree *tree, NodeId start)
 Simplify all nodes in the tree starting with this one. More...
 
void celeritas::orangeinp::simplify (CsgTree *tree, NodeId start)
 Iteratively simplify all nodes in the tree. More...
 
CsgTree celeritas::orangeinp::transform_negated_joins (CsgTree const &tree)
 Simplify negated joins using De Morgan's law. More...
 
std::string celeritas::orangeinp::build_infix_string (CsgTree const &tree, NodeId n)
 Convert a node to an infix string expression.
 
std::vector< LocalSurfaceId > celeritas::orangeinp::calc_surfaces (CsgTree const &tree)
 Construct the sorted set of all surfaces that are part of the tree. More...
 

Detailed Description

Free functions to apply to a CSG tree.

Function Documentation

◆ calc_surfaces()

std::vector< LocalSurfaceId > celeritas::orangeinp::calc_surfaces ( CsgTree const &  tree)

Construct the sorted set of all surfaces that are part of the tree.

This list removes surfaces that have been eliminated by logical replacement. Thanks to the CSG tree's deduplication, each surface should appear in the tree at most once.

◆ replace_and_simplify()

std::vector< NodeId > celeritas::orangeinp::replace_and_simplify ( CsgTree tree,
NodeId  repl_key,
Node  repl_value 
)

Replace the given node ID with the replacement node.

This recurses through daughters of "Joined" to simplify their originating surfaces if possible.

  • "negated": non-constant daughter node is replaced with ~b
  • "replaced": non-constant daughter node is replaced with b
  • "joined": for (false, or): all daughters are "false" for (true, and): all daughters are "true"
  • surface: "true"
  • constant: check for contradiction

This operation is at worst O((number of nodes) * (depth of graph)).

◆ simplify()

void celeritas::orangeinp::simplify ( CsgTree tree,
NodeId  start 
)

Iteratively simplify all nodes in the tree.

The input 'start' node should be the minimum node from a replace_down operation. In the worst case, it should take as many sweeps as the depth of the tree.

◆ simplify_up()

orangeinp::NodeId celeritas::orangeinp::simplify_up ( CsgTree tree,
NodeId  start 
)

Simplify all nodes in the tree starting with this one.

Returns
Lowest ID of any simplified node

◆ transform_negated_joins()

CsgTree celeritas::orangeinp::transform_negated_joins ( CsgTree const &  tree)

Simplify negated joins using De Morgan's law.

This is required if the tree's logic expression is used with InfixEvaluator as negated joins are not supported.