17 bool rectangularSection ,
23 m_insideRadius(fabs(insideRadius)),
24 m_outsideRadius(fabs(outsideRadius)),
25 m_rectSection(rectangularSection),
26 m_rectSectionHeight(fabs(rectSectionHeight)),
27 m_angle_rad(fabs(angle_rad)) {
38 m_rectSectionHeight(0),
64 :
static_cast<unsigned>(
69 unsigned vertCount = (sweepSteps + (closed ? 0 : 1)) *
72 unsigned facesCount = sweepSteps * sectSteps * 2;
74 unsigned faceNormCount = (sweepSteps + (closed ? 0 : 1)) *
76 if (!closed) facesCount += (
m_rectSection ? 2 : sectSteps) * 2;
79 faceNormCount + (closed ? 0 : 2))) {
85 std::vector<CCVector3> sectPoints;
87 sectPoints.resize(sectSteps);
88 }
catch (
const std::bad_alloc&) {
95 double sectStep_rad = (2.0 *
M_PI) / sectSteps;
102 sectPoints[1].x = -sectPoints[0].x;
103 sectPoints[1].z = sectPoints[0].z;
104 sectPoints[2].x = sectPoints[1].x;
105 sectPoints[2].z = -sectPoints[1].z;
106 sectPoints[3].x = -sectPoints[2].x;
107 sectPoints[3].z = sectPoints[2].z;
110 for (
unsigned i = 0; i < sectSteps; ++i) {
111 double sect_angle_rad = i * sectStep_rad;
113 cos(sect_angle_rad) * sectionRadius);
115 sin(sect_angle_rad) * sectionRadius);
125 for (
unsigned t = 0; t < (closed ? sweepSteps : sweepSteps + 1); ++t) {
132 for (
unsigned i = 0; i < sectSteps; ++i) {
133 CCVector3 P(sweepU.
x * (sweepRadius + sectPoints[i].x),
134 sweepU.
y * (sweepRadius + sectPoints[i].x),
150 for (
unsigned i = 0; i < sectSteps; ++i) {
151 double sectAngle_rad = i * sectStep_rad;
153 CCVector3(cos(sectAngle_rad), 0.0, sin(sectAngle_rad))
189 for (
unsigned t = 0; t < sweepSteps; ++t) {
190 unsigned sweepStart = t * sectSteps;
191 for (
unsigned i = 0; i < sectSteps; ++i) {
192 unsigned iNext = (i + 1) % sectSteps;
194 (sweepStart + i + sectSteps) % vertCount,
195 (sweepStart + iNext + sectSteps) % vertCount);
199 (sweepStart + i + sectSteps) % faceNormCount,
200 (sweepStart + i + sectSteps) % faceNormCount);
204 (sweepStart + i + sectSteps) % faceNormCount,
205 (sweepStart + iNext + sectSteps) % faceNormCount);
207 (sweepStart + iNext + sectSteps) % vertCount,
212 (sweepStart + i + sectSteps) % faceNormCount,
217 (sweepStart + iNext + sectSteps) % faceNormCount,
223 unsigned lastSectionShift = sweepSteps * sectSteps;
233 addTriangle(lastSectionShift, lastSectionShift + 2,
234 lastSectionShift + 1);
237 addTriangle(lastSectionShift, lastSectionShift + 3,
238 lastSectionShift + 2);
242 unsigned lastSectionCenterShift = vertCount;
244 for (
unsigned i = 0; i < sectSteps; ++i) {
245 unsigned iNext = (i + 1) % sectSteps;
251 for (
unsigned i = 0; i < sectSteps; ++i) {
252 unsigned iNext = (i + 1) % sectSteps;
254 lastSectionShift + iNext, lastSectionShift + i);
270 assert(out.isOpen() && (out.openMode() & QIODevice::WriteOnly));
271 if (dataVersion < 21) {
279 QDataStream outStream(&out);
290 return std::max(
static_cast<short>(21),
303 QDataStream inStream(&in);
Vector3Tpl< PointCoordinateType > CCVector3
Default 3D Vector.
float PointCoordinateType
Type of the coordinates of a (N-D) point.
static bool Error(const char *format,...)
Display an error dialog with formatted message.
static Vector3Tpl fromArray(const int a[3])
Constructor from an int array.
void addElement(const Type &value)
Float version of ccGLMatrixTpl.
virtual void showTriNorms(bool state)
Sets whether to show or not per-triangle normals.
Generic primitive interface.
bool init(unsigned vertCount, bool vertNormals, unsigned faceCount, unsigned faceNormCount)
Inits internal structures.
virtual bool setDrawingPrecision(unsigned steps)
Sets drawing precision.
ccGenericPrimitive * finishCloneJob(ccGenericPrimitive *primitive) const
Finished 'clone' job (vertices color, etc.)
ccPointCloud * vertices()
Returns vertices.
unsigned m_drawPrecision
Drawing precision (for primitives that support this feature)
static const int MIN_DRAWING_PRECISION
Minimum drawing precision.
bool toFile_MeOnly(QFile &out, short dataVersion) const override
Save own object data.
bool fromFile_MeOnly(QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap) override
Loads own object data.
ccGLMatrix m_transformation
Associated transformation (applied to vertices)
short minimumFileVersion_MeOnly() const override
virtual void notifyGeometryUpdate()
NormsIndexesTableType * m_triNormals
Per-triangle normals.
void addTriangle(unsigned i1, unsigned i2, unsigned i3)
Adds a triangle to the mesh.
void addTriangleNormalIndexes(int i1, int i2, int i3)
Adds a triplet of normal indexes for next triangle.
triangleIndexesContainer * m_triVertIndexes
Triangles' vertices indexes (3 per triangle)
static CompressedNormType GetNormIndex(const PointCoordinateType N[])
Returns the compressed index corresponding to a normal vector.
virtual QString getName() const
Returns object name.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
QMultiMap< unsigned, unsigned > LoadedIDMap
Map of loaded unique IDs (old ID --> new ID)
static void CoordsFromDataStream(QDataStream &stream, int flags, PointCoordinateType *out, unsigned count=1)
ccTorus(PointCoordinateType insideRadius, PointCoordinateType outsideRadius, double angle_rad=2.0 *M_PI, bool rectangularSection=false, PointCoordinateType rectSectionHeight=0, const ccGLMatrix *transMat=0, QString name=QString("Torus"), unsigned precision=DEFAULT_DRAWING_PRECISION)
Default constructor.
virtual bool buildUp() override
Builds primitive.
bool toFile_MeOnly(QFile &out, short dataVersion) const override
Save own object data.
double m_angle_rad
Subtended angle (in radians)
PointCoordinateType m_insideRadius
Inside radius.
PointCoordinateType m_rectSectionHeight
Rectangular section height (along Y-axis) if applicable.
bool fromFile_MeOnly(QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap) override
Loads own object data.
bool m_rectSection
Whether torus has a rectangular (true) or circular (false) section.
PointCoordinateType m_outsideRadius
Outside radius.
virtual ccGenericPrimitive * clone() const override
Clones primitive.
short minimumFileVersion_MeOnly() const override
void addPoint(const CCVector3 &P)
Adds a 3D point to the database.
MiniVec< float, N > ceil(const MiniVec< float, N > &a)
bool LessThanEpsilon(float x)
Test a floating point number against our epsilon (a very small number).