1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-21 10:13:43 +03:00
occt/src/Prs3d/Prs3d.cxx
osa e816dce36e 0032086: Visualization - support deferred data loading
1) Extend Poly_Triangulation by mesh purpose, possibility to be cleared and late-load deferred data interfaces.
2) Update BRep_TFace to store list of triangulations istead of single one. And also active one. Update getter and setter of single triangulation and add new methods to interaction with whole triangulations list.
3) Update BRep_Tool to get single triangulation of face according to the input mesh purpose or whole triangulations list.
4) Update BRep_Builder to make face by not only single triangulation but whole triangulations list with specified active one.
5) Add new methods to BRepTools to interact with shape triangulations (Load/Unload/Activate/LoadAll/UnloadAllTriangulation(s))
6) Add new 'tlateload'command for shape to load/unload/activate triangulations.
7) Update 'trinfo' command by '-lods' options to print detailaed information about LODs of this shape
8) Support empty triangulations by selection. Use bounding box selection in this case.
9) Add new 'outdisplist' option to XDispaly command to print list of displayed objects to output variable but not to theDI
10) Add new '-noecho' option to vdisplay command to skip printing of displayed objects to theDI
11) Create new RWMesh_TriangulationSource as mesh data wrapper for delayed triangulation loading.
12) Create new RWMesh_TriangulationReader as base interface for reading primitive array from the buffer.
13) Cache nodes/triangles number defined in glTF file
14) Use RWMesh_TriangulationSource class as base of RWGltf_GltfLatePrimitiveArray one and RWMesh_TriangulationReader class as base of RWGltf_TriangulationReader one
15) Add possibilty to support of LODs by glTF reader. It is possible to skip data loading and load them later
16) Add new '-skiplateloading' (to skip triangulation loading), '-keeplate' (to keep information about deferred storage to load/unload triangulation later),
'-toprintdebuginfo' (to print additional debug information) options to ReadGltf command
17) Add new test of glTF late loading
2021-03-27 13:46:02 +03:00

174 lines
5.8 KiB
C++

// Created on: 1993-08-27
// Created by: Jean-Louis FRENKEL
// Copyright (c) 1993-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <Prs3d.hxx>
#include <gp_Pnt.hxx>
#include <Graphic3d_ArrayOfSegments.hxx>
#include <Graphic3d_Group.hxx>
#include <Poly_Connect.hxx>
#include <Poly_Triangulation.hxx>
#include <Prs3d_LineAspect.hxx>
// =========================================================================
// function : AddFreeEdges
// purpose :
// =========================================================================
void Prs3d::AddFreeEdges (TColgp_SequenceOfPnt& theSegments,
const Handle(Poly_Triangulation)& thePolyTri,
const gp_Trsf& theLocation)
{
if (thePolyTri.IsNull() || !thePolyTri->HasGeometry())
{
return;
}
// Build the connect tool.
Poly_Connect aPolyConnect (thePolyTri);
Standard_Integer aNbTriangles = thePolyTri->NbTriangles();
Standard_Integer aT[3];
Standard_Integer aN[3];
// Count the free edges.
Standard_Integer aNbFree = 0;
for (Standard_Integer anI = 1; anI <= aNbTriangles; ++anI)
{
aPolyConnect.Triangles (anI, aT[0], aT[1], aT[2]);
for (Standard_Integer aJ = 0; aJ < 3; ++aJ)
{
if (aT[aJ] == 0)
{
++aNbFree;
}
}
}
if (aNbFree == 0)
{
return;
}
TColStd_Array1OfInteger aFree (1, 2 * aNbFree);
Standard_Integer aFreeIndex = 1;
for (Standard_Integer anI = 1; anI <= aNbTriangles; ++anI)
{
aPolyConnect.Triangles (anI, aT[0], aT[1], aT[2]);
thePolyTri->Triangle (anI).Get (aN[0], aN[1], aN[2]);
for (Standard_Integer aJ = 0; aJ < 3; aJ++)
{
Standard_Integer k = (aJ + 1) % 3;
if (aT[aJ] == 0)
{
aFree (aFreeIndex) = aN[aJ];
aFree (aFreeIndex + 1) = aN[k];
aFreeIndex += 2;
}
}
}
// free edges
Standard_Integer aFreeHalfNb = aFree.Length() / 2;
for (Standard_Integer anI = 1; anI <= aFreeHalfNb; ++anI)
{
const gp_Pnt aPoint1 = thePolyTri->Node (aFree (2 * anI - 1)).Transformed (theLocation);
const gp_Pnt aPoint2 = thePolyTri->Node (aFree (2 * anI )).Transformed (theLocation);
theSegments.Append (aPoint1);
theSegments.Append (aPoint2);
}
}
//=======================================================================
//function : MatchSegment
//purpose :
//=======================================================================
Standard_Boolean Prs3d::MatchSegment
(const Standard_Real X,
const Standard_Real Y,
const Standard_Real Z,
const Standard_Real aDistance,
const gp_Pnt& P1,
const gp_Pnt& P2,
Standard_Real& dist)
{
Standard_Real X1,Y1,Z1,X2,Y2,Z2;
P1.Coord(X1,Y1,Z1); P2.Coord(X2,Y2,Z2);
Standard_Real DX = X2-X1;
Standard_Real DY = Y2-Y1;
Standard_Real DZ = Z2-Z1;
Standard_Real Dist = DX*DX + DY*DY + DZ*DZ;
if (Dist == 0.) return Standard_False;
Standard_Real Lambda = ((X-X1)*DX + (Y-Y1)*DY + (Z-Z1)*DZ)/Dist;
if ( Lambda < 0. || Lambda > 1. ) return Standard_False;
dist = Abs(X-X1-Lambda*DX) +
Abs(Y-Y1-Lambda*DY) +
Abs(Z-Z1-Lambda*DZ);
return (dist < aDistance);
}
//==================================================================
// function: PrimitivesFromPolylines
// purpose:
//==================================================================
Handle(Graphic3d_ArrayOfPrimitives) Prs3d::PrimitivesFromPolylines (const Prs3d_NListOfSequenceOfPnt& thePoints)
{
if (thePoints.IsEmpty())
{
return Handle(Graphic3d_ArrayOfPrimitives)();
}
Standard_Integer aNbVertices = 0;
for (Prs3d_NListOfSequenceOfPnt::Iterator anIt (thePoints); anIt.More(); anIt.Next())
{
aNbVertices += anIt.Value()->Length();
}
const Standard_Integer aSegmentEdgeNb = (aNbVertices - thePoints.Size()) * 2;
Handle(Graphic3d_ArrayOfSegments) aSegments = new Graphic3d_ArrayOfSegments (aNbVertices, aSegmentEdgeNb);
for (Prs3d_NListOfSequenceOfPnt::Iterator anIt (thePoints); anIt.More(); anIt.Next())
{
const Handle(TColgp_HSequenceOfPnt)& aPoints = anIt.Value();
Standard_Integer aSegmentEdge = aSegments->VertexNumber() + 1;
aSegments->AddVertex (aPoints->First());
for (Standard_Integer aPntIter = aPoints->Lower() + 1; aPntIter <= aPoints->Upper(); ++aPntIter)
{
aSegments->AddVertex (aPoints->Value (aPntIter));
aSegments->AddEdge ( aSegmentEdge);
aSegments->AddEdge (++aSegmentEdge);
}
}
return aSegments;
}
//==================================================================
// function: AddPrimitivesGroup
// purpose:
//==================================================================
void Prs3d::AddPrimitivesGroup (const Handle(Prs3d_Presentation)& thePrs,
const Handle(Prs3d_LineAspect)& theAspect,
Prs3d_NListOfSequenceOfPnt& thePolylines)
{
Handle(Graphic3d_ArrayOfPrimitives) aPrims = Prs3d::PrimitivesFromPolylines (thePolylines);
thePolylines.Clear();
if (!aPrims.IsNull())
{
Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
aGroup->SetPrimitivesAspect (theAspect->Aspect());
aGroup->AddPrimitiveArray (aPrims);
}
}