ONX_Model::ModelGeometryFromXXX functions not implemented?


#1

I’m trying to update my code from openNURBS 5.0 to openNURBS 6.0, and it’s requiring a huge number of changes. One problem seems to be that the various “table” arrays for things in the ONX_Model have gone away.

I was just trying to replace

onx_model->m_object_table [index]

with

onx_model->ModelGeometryFromUnsignedIndex (index)

My immediate problem with this is that ModelGeometryFromUnsignedIndex isn’t declared const, which is tripping up my code. But when I tried to look at the implementation and see whether its un-const-ness was required, I discovered there is no implementation?! If I do

ack ModelGeometryFrom

all I get is

opennurbs_extensions.h
1249:  ON_ModelGeometryComponent ModelGeometryFromIndex(
1252:  ON_ModelGeometryComponent ModelGeometryFromUnsignedIndex(
1255:  ON_ModelGeometryComponent ModelGeometryFromId(

ie each of them appears only once, and they have no function body anywhere?


(Dale Fugier) #2

Hi @colomon,

When moving from openNURBS 5 to 6, it’s best to convert your for loops that iterated the old tables, found on ONX_Model, to model component iterators. For example, to iterate the model geometry you can do this:

ONX_Model model;
...
ONX_ModelComponentIterator it(model, ON_ModelComponent::Type::ModelGeometry);
const ON_ModelComponent* model_component = nullptr;
for (model_component = it.FirstComponent(); nullptr != model_component; model_component = it.NextComponent())
{
  const ON_ModelGeometryComponent* model_geometry = ON_ModelGeometryComponent::Cast(model_component);
  if (nullptr != model_geometry)
  {
    const ON_3dmObjectAttributes* attributes = model_geometry->Attributes(nullptr);
    if (nullptr != attributes && !attributes->IsInstanceDefinitionObject())
    {
      const ON_Geometry* geometry = model_geometry->Geometry(nullptr);
      if (nullptr != geometry)
      {
        bool rc = ProcessModelGeometry(geometry, attributes);
        // TODO...
      }
    }
  }
}

To iterate a different ‘table’, just create an model component iterator and and specify a different model component type (enum).

Does this help?

– Dale


#3

That doesn’t really help, as I am actually trying to do random access lookup via the index here rather than iterating through everything.

I’m not seeing any obvious reason I cannot just store an ON_Object pointer instead of the index here, which I guess should be a reasonable workaround for what I need.


(Dale Fugier) #4

Hi @colomon,

Use:

ON_ModelComponentReference ComponentFromIndex(
    ON_ModelComponent::Type component_type,
    int component_model_index
    ) const;    

ON_ModelComponentReference ComponentFromUnsignedIndex(
    ON_ModelComponent::Type component_type,
    unsigned int component_model_index
    ) const;    

ON_ModelComponentReference ComponentFromId(
    ON_ModelComponent::Type component_type,
    ON_UUID component_model_id
    ) const;  

For example:

const ON_ModelComponentReference& model_component_ref = model.ComponentFromId(ON_ModelComponent::Type::ModelGeometry, geometry_id);
const ON_ModelGeometryComponent* model_geometry = ON_ModelGeometryComponent::Cast(model_component_ref.ModelComponent());
if (nullptr != model_geometry)
{
  const ON_Geometry* geometry = model_geometry->Geometry(nullptr);
  if (nullptr != geometry)
  {
     // TODO....

– Dale


#5

Index wasn’t working for me at all, but I changed things to use the iterator to go over the entire file and then used the UUID as a random access pointer, and that seems to be working for me.