ENH: provide xfer methods for the meshed surface components.

- the surfMesh classes where originally designed with limited
  (protected) access to the underlying components. This is to
  avoid unintentional direct changes, since these can quickly
  lead to inconsistencies with the topology addressing etc.

  However, if we wish to efficiently adjust surfaces, it is useful
  to modify the components directly.
  The compromise is to provide 'xfer' methods:
    - xferFaces()
    - xferPoints()
    - xferZones()
  These transfer the contents to an Xfer container for reuse, while
  also resetting the topology addressing.  To apply the changes,
  the reset() method is used.
This commit is contained in:
Mark Olesen 2016-11-12 23:42:17 +01:00
parent d2b4284271
commit 52b6c49b4f
9 changed files with 110 additions and 13 deletions

View File

@ -532,6 +532,16 @@ void Foam::MeshedSurface<Face>::scalePoints(const scalar scaleFactor)
}
template<class Face>
void Foam::MeshedSurface<Face>::reset
(
const Xfer<MeshedSurface<Face>>& surf
)
{
transfer(surf());
}
template<class Face>
void Foam::MeshedSurface<Face>::reset
(
@ -1112,12 +1122,11 @@ void Foam::MeshedSurface<Face>::transfer
MeshedSurface<Face>& surf
)
{
reset
(
xferMove(surf.storedPoints()),
xferMove(surf.storedFaces()),
xferMove(surf.storedZones())
);
ParentType::clearOut();
this->storedPoints().transfer(surf.storedPoints());
this->storedFaces().transfer(surf.storedFaces());
this->storedZones().transfer(surf.storedZones());
surf.clear();
}
@ -1167,12 +1176,43 @@ void Foam::MeshedSurface<Face>::transfer
template<class Face>
Foam::Xfer<Foam::MeshedSurface<Face>> Foam::MeshedSurface<Face>::xfer()
Foam::Xfer<Foam::MeshedSurface<Face>>
Foam::MeshedSurface<Face>::xfer()
{
return xferMove(*this);
}
template<class Face>
Foam::Xfer<Foam::List<Face>>
Foam::MeshedSurface<Face>::xferFaces()
{
// Topology changed because of transfer
ParentType::clearOut();
return this->storedFaces().xfer();
}
template<class Face>
Foam::Xfer<Foam::List<Foam::point>>
Foam::MeshedSurface<Face>::xferPoints()
{
// Topology changed because of transfer
ParentType::clearOut();
return this->storedPoints().xfer();
}
template<class Face>
Foam::Xfer<Foam::surfZoneList>
Foam::MeshedSurface<Face>::xferZones()
{
return this->storedZones().xfer();
}
// Read from file, determine format from extension
template<class Face>
bool Foam::MeshedSurface<Face>::read(const fileName& name)

View File

@ -405,6 +405,12 @@ public:
//- Scale points. A non-positive factor is ignored
virtual void scalePoints(const scalar);
//- Reset by transferring contents of the argument and annul it
virtual void reset
(
const Xfer<MeshedSurface<Face>>&
);
//- Reset primitive data (points, faces and zones)
// Note, optimized to avoid overwriting data (with Xfer::null)
virtual void reset
@ -476,6 +482,15 @@ public:
//- Transfer contents to the Xfer container
Xfer<MeshedSurface<Face>> xfer();
//- Transfer stored faces to an Xfer container
Xfer<List<Face>> xferFaces();
//- Transfer stored points to an Xfer container
Xfer<List<point>> xferPoints();
//- Transfer stored zones to an Xfer container
Xfer<surfZoneList> xferZones();
// Read

View File

@ -152,7 +152,7 @@ public:
//- Clear primitive data (points, faces and zones)
void clear();
//- Reset primitive data (points, faces and zones)
//- Reset primitive data (faces and zones)
// Note, optimized to avoid overwriting data (with Xfer::null)
void resetFaces
(

View File

@ -722,6 +722,14 @@ Foam::UnsortedMeshedSurface<Face>::xfer()
}
template<class Face>
Foam::Xfer<Foam::labelList>
Foam::UnsortedMeshedSurface<Face>::xferZoneIds()
{
return this->storedZoneIds().xfer();
}
// Read from file, determine format from extension
template<class Face>
bool Foam::UnsortedMeshedSurface<Face>::read(const fileName& name)

View File

@ -366,6 +366,9 @@ public:
//- Transfer contents to the Xfer container
Xfer<UnsortedMeshedSurface<Face>> xfer();
//- Transfer stored zoneIds to an Xfer container
Xfer<labelList> xferZoneIds();
// Read

View File

@ -272,6 +272,27 @@ void Foam::surfMesh::resetPrimitives
}
void Foam::surfMesh::resetPrimitives
(
const Xfer<List<point>>& points,
const Xfer<faceList>& faces,
const Xfer<surfZoneList>& zones,
const bool validate
)
{
// Clear addressing.
clearOut();
Allocator::reset(points, faces, zones);
this->updateRefs();
if (validate)
{
checkZones();
}
}
void Foam::surfMesh::transfer
(
MeshedSurface<face>& surf
@ -288,7 +309,8 @@ void Foam::surfMesh::transfer
}
Foam::Xfer<Foam::MeshedSurface<Foam::face>> Foam::surfMesh::xfer()
Foam::Xfer<Foam::MeshedSurface<Foam::face>>
Foam::surfMesh::xfer()
{
Xfer<MeshedSurface<face>> xf;

View File

@ -277,6 +277,15 @@ public:
const bool validate = true
);
//- Reset mesh primitive data.
void resetPrimitives
(
const Xfer<List<point>>& points,
const Xfer<faceList>& faces,
const Xfer<surfZoneList>& zones,
const bool validate = true
);
//- Transfer the contents of the argument and annul the argument
void transfer(MeshedSurface<face>&);

View File

@ -94,7 +94,7 @@ bool Foam::triSurface::readVTK(const fileName& fName)
(
tris.xfer(),
patches,
xferCopy<List<point>>(surf.points())
surf.xferPoints()
);
return true;

View File

@ -270,7 +270,7 @@ public:
const bool reuse
);
//- Construct from triangles, patches, points.
//- Construct by transferring (triangles, points) components.
triSurface
(
const Xfer<List<labelledTri>>&,
@ -278,7 +278,7 @@ public:
const Xfer<List<point>>&
);
//- Construct from triangles, points. Set patchnames to default.
//- Construct from triangles, points. Set patch names to default.
triSurface(const List<labelledTri>&, const pointField&);
//- Construct from triangles, points. Set region to 0 and default
@ -299,7 +299,7 @@ public:
//- Destructor
~triSurface();
virtual ~triSurface();
void clearOut();