Exemplo n.º 1
0
int ON_Object::GetUserStrings(
  ON_ClassArray<ON_UserString>& user_strings
  ) const
{
  const int count0 = user_strings.Count();
  const ON_UserStringList* us = ON_UserStringList::Cast(GetUserData(ON_UserStringList::m_ON_UserStringList_class_id.Uuid()));
  if ( us )
    user_strings.Append(us->m_e.Count(),us->m_e.Array());

  return user_strings.Count() - count0;
}
Exemplo n.º 2
0
RH_C_FUNCTION ON_ClassArray<ON_UserString>* ON_Object_GetUserStrings(const ON_Object* pObject, int* count)
{
  ON_ClassArray<ON_UserString>* rc = NULL;
  if( pObject && count )
  {
    rc = new ON_ClassArray<ON_UserString>();
    *count = pObject->GetUserStrings(*rc);
    if( rc->Count()<1 )
    {
      delete rc;
      rc = NULL;
    }
  }
  return rc;
}
Exemplo n.º 3
0
void CMeshDirDrawCallback::DrawMiddleground( CRhinoViewport& vp, CRhinoDoc& )
{
  int mi, mcnt, fi, fcnt, vi, vcnt;
  mcnt = m_mesh_list.Count();
  for( mi = 0; mi < mcnt; mi++ )
  {
    ON_Color saved_color = vp.DrawColor();
    CMeshDir& md = m_mesh_list[mi];

    if( m_draw_face_normals )
    {
      fcnt = md.m_face_center.Count();
      vp.SetDrawColor( m_face_normal_color );
      for( fi = 0; fi < fcnt; fi++ )
      {
        vp.DrawDirectionArrow( md.m_face_center[fi], md.m_face_normal[fi] );
      }
    }

    if( m_draw_vertex_normals )
    {
      if ( md.m_mesh->HasVertexNormals() )
      {
        vp.SetDrawColor( m_vertex_normal_color );
        vcnt = md.m_mesh->m_V.Count();
        for( vi = 0; vi < vcnt; vi++ )
        {
          vp.DrawDirectionArrow( ON_3dPoint(md.m_mesh->m_V[vi]), ON_3dVector(md.m_mesh->m_N[vi]) );
        }
      }
    }

    vp.SetDrawColor( saved_color );
  }
}
void CSampleImportGeomviewPlugIn::AddFileType( ON_ClassArray<CRhinoFileType>& extensions, const CRhinoFileReadOptions& options )
{
  // Description:
  //   When Rhino gets ready to display either the open or import file dialog,
  //   it calls AddFileType() once for each loaded file import plug-in.
  // Parameters:
  //   extensions [in] Append your supported file type extensions to this list.
  //   options [in] File write options.
  // Example:
  //   If your plug-in imports "Geometry Files" that have a ".geo" extension,
  //   then your AddToFileType(....) would look like the following:
  //
  //   CImportPlugIn::AddToFileType(ON_ClassArray<CRhinoFileType>& extensions, const CRhinoFileReadOptions& options)
  //   {
  //      CRhinoFileType ft(PlugInID(), L"Geometry Files (*.geo)", L"geo");
  //      extensions.Append(ft);
  //   }

  // TODO: Add supported file extensions here.
  CRhinoFileType ft;
  ft.SetFileTypePlugInID( PlugInID() );
  ft.FileTypeDescription( L"Geomview OFF (*.off)" );
  ft.AddFileTypeExtension( L"off" );
  extensions.Append( ft );
}
Exemplo n.º 5
0
RH_C_FUNCTION ON_SimpleArray<ON_Polyline*>* ON_Intersect_MeshMesh1(const ON_Mesh* pConstMeshA, const ON_Mesh* pConstMeshB, int* polyline_count, double tolerance)
{
  ON_SimpleArray<ON_Polyline*>* rc = NULL;
  if( polyline_count ) *polyline_count = 0;
  if( pConstMeshA && pConstMeshB && polyline_count )
  {
    ON_ClassArray<ON_MMX_Polyline> plines;
    ON_ClassArray<ON_MMX_Polyline> overlapplines;
    if(::ON_MeshMeshIntersect(pConstMeshA, pConstMeshB, plines, overlapplines, tolerance, tolerance))
    {
      rc = new ON_SimpleArray<ON_Polyline*>();
      for( int i=0; i<plines.Count(); i++ )
      {
        ON_Polyline* pl = new ON_Polyline();
        const ON_MMX_Polyline& mmxpoly = plines[i];
        int c = mmxpoly.Count();
        for( int j=0; j<c; j++ )
          pl->Append(mmxpoly[j].m_A.m_P);
        pl->Clean(ON_ZERO_TOLERANCE);
        if( !pl->IsValid() )
        {
          delete pl;
          continue;
        }
        rc->Append(pl);
      }
      for( int i=0; i<overlapplines.Count(); i++ )
      {
        ON_Polyline* pl = new ON_Polyline();
        const ON_MMX_Polyline& mmxpoly = overlapplines[i];
        int c = mmxpoly.Count();
        for( int j=0; i<c; i++ )
          pl->Append(mmxpoly[j].m_A.m_P);
        pl->Clean(ON_ZERO_TOLERANCE);
        if( !pl->IsValid() )
        {
          delete pl;
          continue;
        }
        rc->Append(pl);
      }
      *polyline_count = rc->Count();
    }
  }
  return rc;
}
Exemplo n.º 6
0
int ON_Object::GetUserStringKeys(
  ON_ClassArray<ON_wString>& user_string_keys
  ) const
{
  const int count0 = user_string_keys.Count();
  const ON_UserStringList* us = ON_UserStringList::Cast(GetUserData(ON_UserStringList::m_ON_UserStringList_class_id.Uuid()));
  if ( us )
  {
    user_string_keys.Reserve( count0 + us->m_e.Count() );
    for (int i = 0; i < us->m_e.Count(); i++ )
    {
      user_string_keys.Append(us->m_e[i].m_key);
    }
  }

  return user_string_keys.Count() - count0;
}
Exemplo n.º 7
0
static void
test_psi(ON_3dPoint &p, ON_Surface &s)
{
    ON_wString wstr;
    ON_TextLog textlog(wstr);
    ON_ClassArray<ON_PX_EVENT> x;

    // Use default tolerance
    ON_Intersect(p, s, x);

    // XXX: How to simply show a surface?
    bu_log("(%f,%f,%f) and a surface:\n", p[0], p[1], p[2]);
    if (x.Count() == 0) {
	bu_log("No intersection.\n");
    } else {
	for (int i = 0; i < x.Count(); i++)
	    x[i].Dump(textlog);
	ON_String str(wstr);
	bu_log(str.Array());
    }
    bu_log("\n\n");
}
Exemplo n.º 8
0
static void
test_ppi(ON_3dPoint &p1, ON_3dPoint &p2)
{
    ON_wString wstr;
    ON_TextLog textlog(wstr);
    ON_ClassArray<ON_PX_EVENT> x;

    // Use default tolerance
    ON_Intersect(p1, p2, x);

    bu_log("(%f,%f,%f) and (%f,%f,%f):\n", p1[0], p1[1], p1[2], p2[0], p2[1], p2[2]);

    if (x.Count() == 0) {
	bu_log("No intersection.\n");
    } else {
	for (int i = 0; i < x.Count(); i++)
	    x[i].Dump(textlog);
	ON_String str(wstr);
	bu_log(str.Array());
    }
    bu_log("\n\n");
}
Exemplo n.º 9
0
static void
test_pci(ON_3dPoint &p, ON_Curve &c)
{
    ON_wString wstr;
    ON_TextLog textlog(wstr);
    ON_ClassArray<ON_PX_EVENT> x;

    // Use default tolerance
    ON_Intersect(p, c, x);

    ON_3dPoint start = c.PointAtStart();
    ON_3dPoint end = c.PointAtEnd();
    bu_log("(%f,%f,%f) and [(%f,%f,%f) to (%f,%f,%f)]:\n",
	   p[0], p[1], p[2], start[0], start[1], start[2], end[0], end[1], end[2]);
    if (x.Count() == 0) {
	bu_log("No intersection.\n");
    } else {
	for (int i = 0; i < x.Count(); i++)
	    x[i].Dump(textlog);
	ON_String str(wstr);
	bu_log(str.Array());
    }
    bu_log("\n\n");
}
Exemplo n.º 10
0
RH_C_FUNCTION ON_MassProperties* ON_Hatch_AreaMassProperties(const ON_Hatch* pConstHatch, double rel_tol, double abs_tol)
{
  ON_MassProperties* rc = NULL;
  if( pConstHatch )
  {
    ON_BoundingBox bbox = pConstHatch->BoundingBox();
    ON_3dPoint basepoint = bbox.Center();
    basepoint = pConstHatch->Plane().ClosestPointTo(basepoint);

    ON_ClassArray<ON_MassProperties> list;

    for( int i=0; i<pConstHatch->LoopCount(); i++ )
    {
      const ON_HatchLoop* pLoop = pConstHatch->Loop(i);
      if( NULL==pLoop )
        continue;
      ON_Curve* pCurve = pConstHatch->LoopCurve3d(i);
      if( NULL==pCurve )
        continue;
      
      ON_MassProperties mp;
      if( pCurve->AreaMassProperties(basepoint, pConstHatch->Plane().Normal(), mp, true, true, true, true, rel_tol, abs_tol) )
      {
        mp.m_mass = fabs(mp.m_mass);
        if( pLoop->Type() == ON_HatchLoop::ltInner )
          mp.m_mass = -mp.m_mass;

        list.Append(mp);
      }
      delete pCurve;
    }

    if( list.Count()==1 )
    {
      rc = new ON_MassProperties();
      *rc = list[0];
    }
    else if( list.Count()>1 )
    {
      int count = list.Count();
      const ON_MassProperties* pieces = list.Array();
      rc = new ON_MassProperties();
      if( !rc->Sum(count, pieces) )
      {
        delete rc;
        rc = NULL;
      }
    }
  }
  return rc;
}
Exemplo n.º 11
0
/**
 * Outputs an array of the same size as this.m_V.Count() in which the
 * ith element of the array is an array with all of the faces that use
 * the ith vertex
 */
int GenerateFaceConnectivityList(
    ON_Mesh *mesh,
    ON_ClassArray<ON_SimpleArray<int> > faces
    )
{
    faces.Empty();
    int n_vertices;
    for (int i = 0; i < mesh->m_F.Count(); i++) {
	ON_MeshFace face = mesh->m_F[i];
	if (face.IsTriangle()) {
	    n_vertices = 3;
	} else {
	    n_vertices = 4;
	}
	for (int j = 0; j < n_vertices; j++) {
	    faces[face.vi[j]].Append(i);
	}
    }
    return 0;
}
void CSampleExportMeshPlugIn::AddFileType( ON_ClassArray<CRhinoFileType>& extensions, const CRhinoFileWriteOptions& options )
{
  // Description:
  //   When Rhino gets ready to display either the save or export file dialog,
  //   it calls AddFileType() once for each loaded file export plug-in.
  // Parameters:
  //   extensions [in] Append your supported file type extensions to this list.
  //   options [in] File write options.
  // Example:
  //   If your plug-in exports "Geometry Files" that have a ".geo" extension,
  //   then your AddToFileType(....) would look like the following:
  //
  //   CExportPlugIn::AddToFileType(ON_ClassArray<CRhinoFileType>&  extensions, const CRhinoFileWriteOptions& options)
  //   {
  //      CRhinoFileType ft(PlugInID(), L"Geometry Files (*.geo)", L"geo");
  //      extensions.Append(ft);
  //   }

  // TODO: Add supported file extensions here.
  extensions.Append( CRhinoFileType(PlugInID(), L"Sample Mesh (*.mesh)", L"mesh") );
}
Exemplo n.º 13
0
int TriIntersections::Faces(
    ON_ClassArray<ON_3dPoint[3]> UNUSED(faces)
    )
{
    if (intersections.Count() == 0) {
	return 0;
    }

    /* first we get an array of all the segments we can use to make
     * our faces.
     */
    ON_SimpleArray<ON_Line> segments; /*the segments we have to make faces */
    ON_SimpleArray<bool> flippable; /* whether or not the segment has direction */
    ON_SimpleArray<bool> segexternal; /* whether or not the segment is from the edge */
    for (int i = 0; i < intersections.Count(); i++) {
	segments.Append(intersections[i]);
	segments.Append(intersections[i]);
	flippable.Append(false);
	flippable.Append(false);
	segexternal.Append(false);
	segexternal.Append(false);
    }

    for (int i = 0; i < 3; i++) {
	if (edges[i].Count() == 2) { /* the edge was never intersected */
	    segments.Append(ON_Line(edges[i][0], edges[i][0]));
	    flippable.Append(true);
	    segexternal.Append(true);
	} else {
	    for (int j = 0; j < (edges[i].Count() - 1); j++) {
		if (dir[i][j] == dir[i][j + 1]) {
		    /* this indicates an error in the intersection data */
		    return -1;
		} else if (dir[i][j] == 0 || dir[i][j+1] == 1) {
		    segments.Append(ON_Line(edges[i][j], edges[i][j+1]));
		    flippable.Append(false);
		    segexternal.Append(true);
		} else {
		    segments.Append(ON_Line(edges[i][j+1], edges[i][j]));
		    flippable.Append(false);
		    segexternal.Append(true);
		}
	    }
	}
    }

    /* Now that the segments are all set up it's time to make them
     * into faces.
     */
    ON_ClassArray<ON_Polyline> outlines;
    ON_SimpleArray<bool> line_external; /* stores whether each polyline is internal */
    ON_Polyline outline;
    while (segments.Count() != 0) {
	outline.Append(segments[0].from);
	outline.Append(segments[0].to);
	segments.Remove(0);

	int i = 0;
	bool ext = false; /* keeps track of the ternality of the path we're assembling */
	while (!outline.IsClosed(tol)) {
	    if (i >= segments.Count()) {
		return -1;
	    } else if (VNEAR_EQUAL(segments[i].from, outline[outline.Count() - 1], tol)) {
		outline.Append(segments[i].to);
	    } else if (VNEAR_EQUAL(segments[i].to, outline[0], tol)) {
		outline.Insert(0, segments[i].from);
	    } else if (VNEAR_EQUAL(segments[i].from, outline[0], tol) && flippable[i]) {
		outline.Insert(0, segments[i].to);
	    } else if (VNEAR_EQUAL(segments[i].to, outline[outline.Count() - 1], tol) && flippable[i]) {
		outline.Append(segments[i].from);
	    } else {
		i++;
		continue;
	    }

	    /* only executed when we append edge i */
	    segments.Remove(i);
	    flippable.Remove(i);
	    ext &= segexternal[i];
	    segexternal.Remove(i);
	    i = 0;
	}
	outlines.Append(outline);
	line_external.Append(ext);
    }
    /* XXX - now we need to setup the ternality tree for the paths */

    return 0;
}