BRL-CAD
combmem.c File Reference
#include "common.h"
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "bu/getopt.h"
#include "./ged_private.h"
Include dependency graph for combmem.c:

Go to the source code of this file.

Macros

#define COMBMEM_GETCOMBTREE(_gedp, _cmd, _name, _dp, _intern, _ntp, _rt_tree_array, _node_count)
 
#define COMBMEM_SET_PART_I(_gedp, _argc, _cmd, _name, _num_params, _intern, _dp, _comb, _node_count, _rt_tree_array)
 
#define COMBMEM_SET_PART_II(_gedp, _opstr, _rt_tree_array_index, _mat)
 
#define COMBMEM_SET_PART_III(_tp, _tree, _rt_tree_array_index, _name)
 
#define COMBMEM_SET_PART_IV(_gedp, _comb, _tree_index, _intern, _final_tree, _node_count, _dp, _rt_tree_array, _old_intern, _old_rt_tree_array, _old_ntp)
 
#define COMBMEM_CHECK_MAT(_tp, _tree_index, _old_rt_tree_array, _mat, _aetvec, _tvec, _svec, _key_pt, _az, _el, _tw, _tx, _ty, _tz, _sa, _sx, _sy, _sz)
 

Enumerations

enum  etypes {
  ETYPES_NULL = -1, ETYPES_ABS, ETYPES_REL, ETYPES_ROT_AET,
  ETYPES_ROT_XYZ, ETYPES_ROT_ARBITRARY_AXIS, ETYPES_TRA, ETYPES_SCA
}
 

Functions

HIDDEN void combmem_mat_aet (matp_t matp, fastf_t az, fastf_t el, fastf_t tw)
 
HIDDEN void combmem_disassemble_rmat (matp_t matp, fastf_t *az, fastf_t *el, fastf_t *tw)
 
HIDDEN int combmem_disassemble_mat (matp_t matp, fastf_t *az, fastf_t *el, fastf_t *tw, fastf_t *tx, fastf_t *ty, fastf_t *tz, fastf_t *sa, fastf_t *sx, fastf_t *sy, fastf_t *sz)
 
HIDDEN void combmem_assemble_mat (matp_t matp, vect_t aetvec, vect_t tvec, hvect_t svec, point_t key_pt, int sflag)
 
HIDDEN void combmem_vls_print_member_info (struct ged *gedp, char op, union tree *itp, enum etypes etype)
 
HIDDEN int combmem_get (struct ged *gedp, int argc, const char *argv[], enum etypes etype)
 
HIDDEN int combmem_set (struct ged *gedp, int argc, const char *argv[], enum etypes etype)
 
HIDDEN int combmem_set_rot (struct ged *gedp, int argc, const char *argv[], enum etypes etype)
 
HIDDEN int combmem_set_arb_rot (struct ged *gedp, int argc, const char *argv[], enum etypes etype)
 
HIDDEN int combmem_set_tra (struct ged *gedp, int argc, const char *argv[], enum etypes etype)
 
HIDDEN int combmem_set_sca (struct ged *gedp, int argc, const char *argv[], enum etypes etype)
 
HIDDEN int combmem_set_empty (struct ged *gedp, int argc, const char *argv[])
 
int ged_combmem (struct ged *gedp, int argc, const char *argv[])
 

Detailed Description

The combmem command.

Definition in file combmem.c.

Macro Definition Documentation

#define COMBMEM_GETCOMBTREE (   _gedp,
  _cmd,
  _name,
  _dp,
  _intern,
  _ntp,
  _rt_tree_array,
  _node_count 
)
#define COMBMEM_SET_PART_I (   _gedp,
  _argc,
  _cmd,
  _name,
  _num_params,
  _intern,
  _dp,
  _comb,
  _node_count,
  _rt_tree_array 
)
Value:
{ \
if (rt_db_get_internal(&(_intern), (_dp), (_gedp)->ged_wdbp->dbip, (matp_t)NULL, &rt_uniresource) < 0) { \
bu_vls_printf((_gedp)->ged_result_str, "Database read error, aborting"); \
return GED_ERROR; \
} \
\
(_comb) = (struct rt_comb_internal *)(_intern).idb_ptr; \
RT_CK_COMB((_comb)); \
(_node_count) = ((_argc) - 2) / (_num_params); /* integer division */ \
if (_node_count) { \
(_rt_tree_array) = (struct rt_tree_array *)bu_calloc((_node_count), sizeof(struct rt_tree_array), "tree list"); \
} else { \
(_rt_tree_array) = (struct rt_tree_array *)0; \
} \
}
int rt_db_get_internal(struct rt_db_internal *ip, const struct directory *dp, const struct db_i *dbip, const mat_t mat, struct resource *resp)
Definition: dir.c:76
#define RT_CK_COMB(_p)
Definition: raytrace.h:955
#define GED_ERROR
Definition: ged.h:61
if(share_geom)
Definition: nmg_mod.c:3829
struct resource rt_uniresource
default. Defined in librt/globals.c
Definition: globals.c:41
void * bu_calloc(size_t nelem, size_t elsize, const char *str)
Definition: malloc.c:321
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694

Definition at line 420 of file combmem.c.

Referenced by combmem_set(), combmem_set_arb_rot(), combmem_set_rot(), combmem_set_sca(), and combmem_set_tra().

#define COMBMEM_SET_PART_II (   _gedp,
  _opstr,
  _rt_tree_array_index,
  _mat 
)
Value:
{ \
db_op_t combmem_set_part_ii_op = db_str2op((_opstr)); \
\
/* Add it to the combination */ \
switch (combmem_set_part_ii_op) { \
(_rt_tree_array_index).tl_op = OP_INTERSECT; \
break; \
(_rt_tree_array_index).tl_op = OP_SUBTRACT; \
break; \
default: \
bu_vls_printf((_gedp)->ged_result_str, "combmem_set: unrecognized relation %c (assuming UNION)\n", (_opstr)[0]); \
case DB_OP_UNION: \
(_rt_tree_array_index).tl_op = OP_UNION; \
break; \
} \
\
MAT_IDN((_mat)); \
}
db_op_t db_str2op(const char *str)
Definition: op.c:31
#define OP_SUBTRACT
Binary: L subtract R.
Definition: raytrace.h:1129
#define OP_INTERSECT
Binary: L intersect R.
Definition: raytrace.h:1128
db_op_t
Definition: op.h:33
Definition: op.h:35
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
#define OP_UNION
Binary: L union R.
Definition: raytrace.h:1127

Definition at line 437 of file combmem.c.

Referenced by combmem_set(), combmem_set_arb_rot(), combmem_set_rot(), combmem_set_sca(), and combmem_set_tra().

#define COMBMEM_SET_PART_III (   _tp,
  _tree,
  _rt_tree_array_index,
  _name 
)
Value:
(_rt_tree_array_index).tl_tree = (_tp); \
(_tp)->tr_l.tl_op = OP_DB_LEAF; \
(_tp)->tr_l.tl_name = bu_strdup(_name); \
(_tp)->tr_l.tl_mat = (matp_t)bu_calloc(1, sizeof(mat_t), "combmem_set: mat");
#define OP_DB_LEAF
Leaf of combination, db fmt.
Definition: raytrace.h:1139
void * bu_calloc(size_t nelem, size_t elsize, const char *str)
Definition: malloc.c:321
#define bu_strdup(s)
Definition: str.h:71

Definition at line 459 of file combmem.c.

Referenced by combmem_set(), combmem_set_arb_rot(), combmem_set_rot(), combmem_set_sca(), and combmem_set_tra().

#define COMBMEM_SET_PART_IV (   _gedp,
  _comb,
  _tree_index,
  _intern,
  _final_tree,
  _node_count,
  _dp,
  _rt_tree_array,
  _old_intern,
  _old_rt_tree_array,
  _old_ntp 
)
Value:
(_comb)->tree = NULL; \
if ((_tree_index)) \
(_final_tree) = (union tree *)db_mkgift_tree((_rt_tree_array), (_node_count), &rt_uniresource); \
(_final_tree) = TREE_NULL; \
RT_DB_INTERNAL_INIT(&(_intern)); \
(_intern).idb_major_type = DB5_MAJORTYPE_BRLCAD; \
(_intern).idb_type = ID_COMBINATION; \
(_intern).idb_meth = &OBJ[ID_COMBINATION]; \
(_intern).idb_ptr = (void *)(_comb); \
(_comb)->tree = (_final_tree); \
if (rt_db_put_internal((_dp), (_gedp)->ged_wdbp->dbip, &(_intern), &rt_uniresource) < 0) { \
bu_vls_printf((_gedp)->ged_result_str, "Unable to write new combination into database.\n"); \
rt_db_free_internal(&(_old_intern)); \
if (_old_rt_tree_array) \
bu_free((void *)(_old_rt_tree_array), "rt_tree_array"); \
db_free_tree((_old_ntp), &rt_uniresource); \
\
return GED_ERROR; \
} \
rt_db_free_internal(&(_old_intern)); \
if (_old_rt_tree_array) \
bu_free((void *)(_old_rt_tree_array), "rt_tree_array"); \
int rt_db_put_internal(struct directory *dp, struct db_i *dbip, struct rt_db_internal *ip, struct resource *resp)
Definition: dir.c:136
union tree * db_mkgift_tree(struct rt_tree_array *trees, size_t subtreecount, struct resource *resp)
Definition: db_comb.c:1016
#define ID_COMBINATION
Combination Record.
Definition: raytrace.h:499
#define GED_ERROR
Definition: ged.h:61
if(share_geom)
Definition: nmg_mod.c:3829
struct resource rt_uniresource
default. Defined in librt/globals.c
Definition: globals.c:41
#define RT_DB_INTERNAL_INIT(_p)
Definition: raytrace.h:199
#define TREE_NULL
Definition: raytrace.h:1181
void db_free_tree(union tree *tp, struct resource *resp)
Definition: db_tree.c:1296
const struct rt_functab OBJ[]
Definition: table.c:159
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
else
Definition: nmg_mod.c:3872
#define idb_type
Definition: raytrace.h:198
void bu_free(void *ptr, const char *str)
Definition: malloc.c:328
void rt_db_free_internal(struct rt_db_internal *ip)
Definition: dir.c:216

Definition at line 466 of file combmem.c.

Referenced by combmem_set(), combmem_set_arb_rot(), combmem_set_rot(), combmem_set_sca(), and combmem_set_tra().

#define COMBMEM_CHECK_MAT (   _tp,
  _tree_index,
  _old_rt_tree_array,
  _mat,
  _aetvec,
  _tvec,
  _svec,
  _key_pt,
  _az,
  _el,
  _tw,
  _tx,
  _ty,
  _tz,
  _sa,
  _sx,
  _sy,
  _sz 
)
Value:
bn_mat_mul((_tp)->tr_l.tl_mat, (_mat), (_old_rt_tree_array)[(_tree_index)].tl_tree->tr_l.tl_mat); \
\
/* If bn_mat_ck fails, it's because scaleX, scaleY and/or scaleZ has been \
* been applied along with rotations. This screws up perpendicularity. \
*/ \
if (bn_mat_ck("combmem_set", (_tp)->tr_l.tl_mat)) { \
combmem_assemble_mat((_mat), (_aetvec), (_tvec), (_svec), (_key_pt), 0); \
bn_mat_mul((_tp)->tr_l.tl_mat, (_mat), (_old_rt_tree_array)[(_tree_index)].tl_tree->tr_l.tl_mat); \
if (bn_mat_ck("combmem_set", (_tp)->tr_l.tl_mat)) { \
MAT_COPY((_tp)->tr_l.tl_mat, (_old_rt_tree_array)[(_tree_index)].tl_tree->tr_l.tl_mat); \
} \
} else { \
/* This will check if the 3x3 rotation part is bad after factoring out scaleX, scaleY and scaleZ. */ \
if (combmem_disassemble_mat((_tp)->tr_l.tl_mat, &(_az), &(_el), &(_tw), &(_tx), &(_ty), &(_tz), &(_sa), &(_sx), &(_sy), &(_sz))) { \
MAT_COPY((_tp)->tr_l.tl_mat, (_old_rt_tree_array)[(_tree_index)].tl_tree->tr_l.tl_mat); \
} \
}
if(share_geom)
Definition: nmg_mod.c:3829
HIDDEN int combmem_disassemble_mat(matp_t matp, fastf_t *az, fastf_t *el, fastf_t *tw, fastf_t *tx, fastf_t *ty, fastf_t *tz, fastf_t *sa, fastf_t *sx, fastf_t *sy, fastf_t *sz)
Definition: combmem.c:145
int bn_mat_ck(const char *title, const mat_t m)
Definition: mat.c:1058
void bn_mat_mul(mat_t o, const mat_t a, const mat_t b)
HIDDEN void combmem_assemble_mat(matp_t matp, vect_t aetvec, vect_t tvec, hvect_t svec, point_t key_pt, int sflag)
Definition: combmem.c:208

Definition at line 499 of file combmem.c.

Referenced by combmem_set(), combmem_set_arb_rot(), combmem_set_rot(), and combmem_set_sca().

Enumeration Type Documentation

enum etypes
Enumerator
ETYPES_NULL 
ETYPES_ABS 
ETYPES_REL 
ETYPES_ROT_AET 
ETYPES_ROT_XYZ 
ETYPES_ROT_ARBITRARY_AXIS 
ETYPES_TRA 
ETYPES_SCA 

Definition at line 35 of file combmem.c.

Function Documentation

HIDDEN void combmem_mat_aet ( matp_t  matp,
fastf_t  az,
fastf_t  el,
fastf_t  tw 
)

Given the azimuth, elevation and twist angles, calculate the rotation part of a 4x4 matrix.

Definition at line 52 of file combmem.c.

Referenced by combmem_assemble_mat(), and combmem_set_rot().

HIDDEN void combmem_disassemble_rmat ( matp_t  matp,
fastf_t az,
fastf_t el,
fastf_t tw 
)

Disassemble the given rotation matrix into az, el, tw.

Definition at line 93 of file combmem.c.

References NEAR_ZERO.

Referenced by combmem_disassemble_mat().

HIDDEN int combmem_disassemble_mat ( matp_t  matp,
fastf_t az,
fastf_t el,
fastf_t tw,
fastf_t tx,
fastf_t ty,
fastf_t tz,
fastf_t sa,
fastf_t sx,
fastf_t sy,
fastf_t sz 
)

Disassemble the given matrix into az, el, tw, tx, ty, tz, sa, sx, sy and sz.

Definition at line 145 of file combmem.c.

References bn_mat_ck(), and combmem_disassemble_rmat().

Referenced by combmem_vls_print_member_info().

Here is the call graph for this function:

HIDDEN void combmem_assemble_mat ( matp_t  matp,
vect_t  aetvec,
vect_t  tvec,
hvect_t  svec,
point_t  key_pt,
int  sflag 
)

Assemble the given aetvec, tvec and svec into a 4x4 matrix using key_pt for rotations and scale.

Definition at line 208 of file combmem.c.

References bn_mat_mul(), bn_mat_xform_about_pt(), combmem_mat_aet(), X, Y, Z, and ZERO.

Referenced by combmem_set(), and combmem_set_sca().

Here is the call graph for this function:

HIDDEN void combmem_vls_print_member_info ( struct ged gedp,
char  op,
union tree itp,
enum etypes  etype 
)

Definition at line 271 of file combmem.c.

References bu_log(), bu_vls_printf(), combmem_disassemble_mat(), ETYPES_ABS, ETYPES_REL, ETYPES_ROT_AET, ETYPES_ROT_ARBITRARY_AXIS, ETYPES_ROT_XYZ, ETYPES_SCA, ETYPES_TRA, ged::ged_result_str, tree::tree_db_leaf::tl_mat, tree::tree_db_leaf::tl_name, and tree::tr_l.

Referenced by combmem_get().

Here is the call graph for this function:

HIDDEN int combmem_get ( struct ged gedp,
int  argc,
const char *  argv[],
enum etypes  etype 
)

Definition at line 371 of file combmem.c.

References BU_ASSERT_LONG, BU_ASSERT_PTR, bu_bomb(), bu_free(), bu_vls_printf(), COMBMEM_GETCOMBTREE, combmem_vls_print_member_info(), db_free_tree(), DB_OP_INTERSECT, DB_OP_SUBTRACT, DB_OP_UNION, GED_ERROR, GED_OK, ged::ged_result_str, OP_DB_LEAF, OP_INTERSECT, OP_SUBTRACT, OP_UNION, RT_CK_TREE, rt_db_free_internal(), rt_uniresource, tree::tree_db_leaf::tl_name, rt_tree_array::tl_tree, and tree::tr_l.

Referenced by ged_combmem().

Here is the call graph for this function:

HIDDEN int combmem_set ( struct ged gedp,
int  argc,
const char *  argv[],
enum etypes  etype 
)

Definition at line 521 of file combmem.c.

References bn_mat_ck(), BU_ALLOC, BU_STR_EQUAL, combmem_assemble_mat(), COMBMEM_CHECK_MAT, COMBMEM_GETCOMBTREE, COMBMEM_SET_PART_I, COMBMEM_SET_PART_II, COMBMEM_SET_PART_III, COMBMEM_SET_PART_IV, db_i::dbi_local2base, rt_wdb::dbip, ETYPES_ABS, ETYPES_REL, GED_ERROR, GED_OK, ged::ged_wdbp, RT_TREE_INIT, tree::tree_db_leaf::tl_mat, tree::tree_db_leaf::tl_name, tree::tr_l, and VSET.

Referenced by ged_combmem().

Here is the call graph for this function:

HIDDEN int combmem_set_rot ( struct ged gedp,
int  argc,
const char *  argv[],
enum etypes  etype 
)
HIDDEN int combmem_set_arb_rot ( struct ged gedp,
int  argc,
const char *  argv[],
enum etypes  etype 
)

Definition at line 713 of file combmem.c.

References bn_mat_arb_rot(), BU_ALLOC, BU_STR_EQUAL, COMBMEM_CHECK_MAT, COMBMEM_GETCOMBTREE, COMBMEM_SET_PART_I, COMBMEM_SET_PART_II, COMBMEM_SET_PART_III, COMBMEM_SET_PART_IV, db_i::dbi_local2base, rt_wdb::dbip, ETYPES_ROT_ARBITRARY_AXIS, GED_ERROR, GED_OK, ged::ged_wdbp, RT_TREE_INIT, tree::tree_db_leaf::tl_mat, tree::tree_db_leaf::tl_name, tree::tr_l, and VSET.

Referenced by ged_combmem().

Here is the call graph for this function:

HIDDEN int combmem_set_tra ( struct ged gedp,
int  argc,
const char *  argv[],
enum etypes  etype 
)

Definition at line 792 of file combmem.c.

References bn_mat_mul(), BU_ALLOC, BU_STR_EQUAL, COMBMEM_GETCOMBTREE, COMBMEM_SET_PART_I, COMBMEM_SET_PART_II, COMBMEM_SET_PART_III, COMBMEM_SET_PART_IV, db_i::dbi_local2base, rt_wdb::dbip, ETYPES_TRA, GED_ERROR, GED_OK, ged::ged_wdbp, RT_TREE_INIT, tree::tree_db_leaf::tl_mat, tree::tree_db_leaf::tl_name, rt_tree_array::tl_tree, tree::tr_l, and VSET.

Referenced by ged_combmem().

Here is the call graph for this function:

HIDDEN int combmem_set_sca ( struct ged gedp,
int  argc,
const char *  argv[],
enum etypes  etype 
)

Definition at line 854 of file combmem.c.

References BU_ALLOC, BU_STR_EQUAL, combmem_assemble_mat(), COMBMEM_CHECK_MAT, COMBMEM_GETCOMBTREE, COMBMEM_SET_PART_I, COMBMEM_SET_PART_II, COMBMEM_SET_PART_III, COMBMEM_SET_PART_IV, db_i::dbi_local2base, rt_wdb::dbip, ETYPES_SCA, GED_ERROR, GED_OK, ged::ged_wdbp, RT_TREE_INIT, tree::tree_db_leaf::tl_mat, tree::tree_db_leaf::tl_name, tree::tr_l, VSET, and VSETALL.

Referenced by ged_combmem().

Here is the call graph for this function:

HIDDEN int combmem_set_empty ( struct ged gedp,
int  argc,
const char *  argv[] 
)

Definition at line 935 of file combmem.c.

References bu_vls_printf(), directory::d_flags, db_free_tree(), db_lookup(), rt_wdb::dbip, GED_ERROR, GED_OK, ged::ged_result_str, ged::ged_wdbp, rt_db_internal::idb_ptr, if(), LOOKUP_NOISY, RT_CK_COMB, rt_db_get_internal(), rt_db_put_internal(), RT_DIR_COMB, RT_DIR_NULL, rt_uniresource, and rt_comb_internal::tree.

Referenced by ged_combmem().

Here is the call graph for this function:

int ged_combmem ( struct ged gedp,
int  argc,
const char *  argv[] 
)

Set/get comb's members.

Definition at line 979 of file combmem.c.

References bu_getopt(), bu_optarg, bu_optind, bu_vls_printf(), bu_vls_trunc(), combmem_get(), combmem_set(), combmem_set_arb_rot(), combmem_set_empty(), combmem_set_rot(), combmem_set_sca(), combmem_set_tra(), ETYPES_ABS, ETYPES_NULL, ETYPES_REL, ETYPES_ROT_AET, ETYPES_ROT_ARBITRARY_AXIS, ETYPES_ROT_XYZ, ETYPES_SCA, ETYPES_TRA, GED_ERROR, GED_HELP, ged::ged_result_str, and usage().

Here is the call graph for this function: