Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches
Channel.h
Go to the documentation of this file.
1//! @file Channel.h
2//! @brief CChannel class definition which is the base class for object channels (UV, normals...)
3//!
4//////////////////////////////////////////////////////////////////////
5
6#if !defined(AFX_CHANNEL_H__79EB93C1_8866_11D3_A029_8FE73A9B677B__INCLUDED_)
7#define AFX_CHANNEL_H__79EB93C1_8866_11D3_A029_8FE73A9B677B__INCLUDED_
8
9#ifdef _MSC_VER
10#pragma once
11#endif // _MSC_VER
12
13#include "PointList.h"
14#include "FaceList.h"
15#include "CustomData.h"
16
17#if !defined(MOOTOOLS_CRUNCHERSDK)
18#include "ChannelPrivate.h"
19#endif
20
21BEGIN_MOOTOOLS_NAMESPACE
22
23//! @enum Channel3DType
24//! @brief The channel type which can be used to cast to the appropriate class
25//! Bitwise operations can be use to test several kind of channel
26typedef enum Channel3DType
27{
28 CHANNEL_TYPE_UNDEFINED = 0x00,
29 CHANNEL_UNKNOWN = 0x00,
30 UVW_CHANNEL = 0x01, //!< Texture channel
31 VC_CHANNEL = 0x04, //!< Vertex color channel
32 WEIGHT_CHANNEL = 0x08, //!< Float value channel
33 POINT_NORMAL_CHANNEL = 0x10, //!< Autogenerated point normal channel (one or several normals per point)
34 FACE_NORMAL_CHANNEL = 0x20, //!< Autogenerated face normal channel (one normal per face)
35 SPEC_NORMAL_CHANNEL = 0x40, //!< User specified normals channel
36 ALL_CHANNELS_TYPE = 0xFFFF,
38
39#define UVW_DEFAULT_CHANNNEL_ID (CDependentChannels::GetFirstChannelIDByType(UVW_CHANNEL))
40#define VC_DEFAULT_CHANNNEL_ID (CDependentChannels::GetFirstChannelIDByType(VC_CHANNEL))
41#define WEIGHT_DEFAULT_CHANNNEL_ID (CDependentChannels::GetFirstChannelIDByType(WEIGHT_CHANNEL))
42#define POINT_NORMAL_DEFAULT_CHANNNEL_ID (CDependentChannels::GetFirstChannelIDByType(POINT_NORMAL_CHANNEL))
43#define FACE_NORMAL_DEFAULT_CHANNNEL_ID (CDependentChannels::GetFirstChannelIDByType(FACE_NORMAL_CHANNEL))
44#define SPEC_NORMAL_DEFAULT_CHANNNEL_ID (CDependentChannels::GetFirstChannelIDByType(SPEC_NORMAL_CHANNEL))
45
46typedef enum CHANNEL_COPY_FLAGS
47{
48 CHANNEL_COPY_DEFAULT = 0x00,
49 CHANNEL_COPY_INHERIT_ID = 0x01, // Inherits ID
50 CHANNEL_COPY_ONLY_VALID = 0x02, // Copy only valid channels
51 CHANNEL_COPY_ADD = 0x04, // Add the copy to the channel list
52 CHANNEL_COPY_EMPTY = 0x08, // Do not copy information
53 CHANNEL_COPY_USEFUL_ONLY = 0x10, // Do not copy channels computed in real time such normals or uvw computed by maaping projection
54 CHANNEL_COPY_CLONE = 0x20, // Duplicate the channel pointer
55} CHANNEL_COPY_FLAGS;
56
57typedef enum CHANNEL_PROPERTIES
58{
59 CHANNEL_NONE = 0x00,
60 CHANNEL_IS_INVALID = 0x01, // The channel is invalid and must not be used
61 CHANNEL_CACHE_DATA = 0x02, // The channel as internal data which might need to be recomputed (ie CSpecNormalChannel). This flag is dependent of the channel type.
62 CHANNEL_INVALID_CACHE = 0x04, // The channel cache should be recomputed
63 CHANNEL_IS_AUTOGENERATED = 0x08, // The channel is computed on the fly (not user defined)
64 CHANNEL_SUPPORT_INCOMPLETE_FACES = 0x10, // Faces can refer to point index which have the POINT_IS_UNUSED flags
65 CHANNEL_HAS_NO_FACE_OR_POINT = 0x20, // The channel does not have face or point but some data of other purpose (it is not destroyed during clean operation, if face size mismatch)
66 CHANNEL_RECOMPUTE_ON_TRIANGULATION = 0x40, // Triangulation requires the channel to be invalidated
67
68 CHANNEL_USER_PROPERTIES1 = 0x01000000,
69 CHANNEL_USER_PROPERTIES2 = 0x02000000,
70 CHANNEL_USER_PROPERTIES3 = 0x04000000,
71 CHANNEL_USER_PROPERTIES4 = 0x08000000,
72} CHANNEL_PROPERTIES;
73
74//! @struct ChannelConnectionInfo
75//! @brief Used by GetChannelPointsConnectedToPoint
77{
78 int chnindex;
79 int face;
81
82//! @class CChannel
83//! @brief A CChannel is the base class for some additional information associated to an object.
84//! @details CChannel is used to store UV textures, vertex colors or anything else through different channel classes (CUVWChannel, CVCChannel, CPointNormalChannel, CSpecNormalChannel...).
85//! @par
86//! CChannel usually contains faces and points, but not necessary such CFaceNormalChannel with only contains a list of vector (one vector per geometry face).\n
87//! When CChannel has faces, **it is assumes** that CChannel::GetFaceList::GetSize = C3DFaceList::GetSize.\n
88//! Some channel faces might be unused, and it that case it is flag with FACE_IS_UNUSED, meaning that the face has no relative data.\n
89//! A CChannel with faces can have any number of points. This number is not necessary the same than object 3D points number, as you can have one or more information per 3D points.\n
90//! @par
91//! CChannel integrates a Clean method which make easier synchronisation between the 3D points and the channel points. Each #i face in the channel is removed if the corresponding face #i face in the object C3DFaceList has the FACE_IS_INVALID flag.
92class DLL_3DFUNCTION CChannel : public CXObject, public CInstanciatedObject
93{
94 friend CDependentChannels;
95
96 DECLARE_SERIAL_XOBJECT(CChannel);
97
98public:
99 CChannel(ChannelID id = CHANNELID_UNDEFINED); //!< You may assign a specific channel id at creation. This is useful to make a known reference between material and front / back UV channel for example. Note : If id = CHANNELID_UNDEFINED, the id is automatically assigned when adding the channel to object channels. If id != CHANNELID_UNDEFINED, the id might be modified if it already exists in object channels
100 virtual ~CChannel(); //!< Use Delete instead, unless the CChannel is created on the stack (take care that it is referenced once only in this case)
101
102 static CChannel *Create(Channel3DType type, ChannelID id = CHANNELID_UNDEFINED); //!< Allocates and creates a new channel. Use Delete if the channel is not attached to a CDependentChannel list. //!< If id = CHANNELID_UNDEFINED, the id is automatically assigned when adding the channel to object channels. If id != CHANNELID_UNDEFINED, the id might be modified if it already exists in object channels
103
104 //! @name Flags informations
105 //! @{
106 void SetFlag(CHANNEL_PROPERTIES flag, bool set);
107 void SetFlags(unsigned int newflags, bool set);
108 bool IsFlagSet(unsigned int flag) const;
109 bool IsOneFlagSet(unsigned int flag) const;
110 CCustomData& GetCustomData();
111 ChannelID GetChannelID() const; //!< The channel ID allows to rely a specific material to a specific channel. This is not a GUID (different object might different channel with the same ID, allowing a material to retrieve the UV channel to use for example)
112 CXString GetTypeString() const;
113
114 //! @}
115
116 //! @name Channel informations
117 //! @{
118 CFaceList *GetFaceList();
119 CPointList *GetPointList();
120
121 //! @}
122
123 //! @name Channel information
124 //! @{
125 void SetFaceList(Channel3DType channeltype, CFaceList *newfaces, bool deletePrevious = true); //!< Attach a face list to the channel. newfaces is owned by the channel, and should not be deleted by the caller
126 void SetPointList(Channel3DType channeltype, CPointList *newpoints, bool deletePrevious = true); //!< Attach a point list to the channel. newpoints is owned by the channel, and should not be deleted by the caller
127 Channel3DType GetType() const;
128
129 //! @}
130
131 void FreeExtra(); //!< Release any extra memory attached to the channel
132
133 //! @name graph functions
134 //! @{
135 void InitGraph(const CGeomInfo *);
136 void DeleteGraph();
137 ChannelConnectionInfo *GetChannelPointsConnectedToPoint(int point, int& size); //!< Return UVs connected to the point. size is the number of ChannelConnectionInfo * array entries for point index
138 ChannelConnectionInfo *GetChannelPointsConnectedToPoint(int point, int& size, int& facesize); //!< facesize is the number of faces connected to the point, which might be different than size if some face has invalid or unused UV
139 CPt *GetChannelPointIndex(int facenbr, int pointindex);
140
141 //! @}
142
143 //! @name Operation on the channel
144 //! @{
145 virtual bool SwapCoordinates(unsigned int swapMode);
146 virtual bool MatrixTransform(const C4x4Matrix& matrix, POINT_PROPERTIES property = POINT_NONE, bool set = TRUE, int index = 0, int count = -1);
147 virtual bool CleanRemoveDuplicateIndex();
148 virtual bool Clean(const CGeomInfo *info, CXUIntArray *newfaceindex = NULL, CXUIntArray *newpointindex = NULL);
149 virtual bool Weld(const CGeomInfo *info, double tolerance);
150
151 //! @}
152
153 //! @name virtual function
154 //! @{
155 virtual bool Compare(const CChannel *channel) const; //!< Return true if the channel have same type and same content
156 virtual bool Compare(const CPt *pt1, const CPt *pt2, double tolerance = 0.0f) const;
157 virtual void Serialize(CXArchive& ar);
158 virtual bool CanBeRecomputed();
159 virtual void Inherit(const CChannel& srcChannels);
160 virtual CChannel *Copy(unsigned int copyFlags) const;
161
162 //! @}
163
164#ifdef _DEBUG
165 unsigned int MemoryStats() const;
166#endif
167
168protected:
169 ChannelID channelID; // A single identifier (for a given Channel3DType). If channelID == CHANNELID_UNDEFINED, then an ID will be assigned when adding the channel to the CDependentChannels
170 Channel3DType type;
171 unsigned int flags;
172
173 CPointList *channelPoints;
174 CFaceList *channelFaces;
175 CCustomData data;
176
177 CChannelGraph *chnGraph;
178 int chnGraphLock;
179
180 unsigned int faceStamp, chnFaceStamp;
181
182 void CreateGraph(const CGeomInfo *); // Use InitGraph
183 void SetChannelID(ChannelID id); // Assign a new channel ID. Call through CDependentChannel which ensure its single for a given type
184};
185
186END_MOOTOOLS_NAMESPACE
187
188#endif // !defined(AFX_CHANNEL_H__79EB93C1_8866_11D3_A029_8FE73A9B677B__INCLUDED_)
Channel3DType
The channel type which can be used to cast to the appropriate class Bitwise operations can be use to ...
Definition Channel.h:27
@ FACE_NORMAL_CHANNEL
Autogenerated face normal channel (one normal per face)
Definition Channel.h:34
@ POINT_NORMAL_CHANNEL
Autogenerated point normal channel (one or several normals per point)
Definition Channel.h:33
@ WEIGHT_CHANNEL
Float value channel.
Definition Channel.h:32
@ SPEC_NORMAL_CHANNEL
User specified normals channel.
Definition Channel.h:35
@ VC_CHANNEL
Vertex color channel.
Definition Channel.h:31
@ UVW_CHANNEL
Texture channel.
Definition Channel.h:30
CCustomData class is a handly class for storing any kind of data.
CFaceList class is the base class for different kind of face list.
POINT_PROPERTIES
Point flags used by any classes that inherit from CPt (C3DPoint, C3DVector...)
Definition Point.h:19
The class defines an x, y, z 3D point which can use int, float or double.
Definition 3DPoint.h:27
A CChannel is the base class for some additional information associated to an object.
Definition Channel.h:93
virtual bool Compare(const CChannel *channel) const
Return true if the channel have same type and same content.
CChannel(ChannelID id=CHANNELID_UNDEFINED)
You may assign a specific channel id at creation. This is useful to make a known reference between ma...
virtual ~CChannel()
Use Delete instead, unless the CChannel is created on the stack (take care that it is referenced once...
void SetFaceList(Channel3DType channeltype, CFaceList *newfaces, bool deletePrevious=true)
Attach a face list to the channel. newfaces is owned by the channel, and should not be deleted by the...
ChannelConnectionInfo * GetChannelPointsConnectedToPoint(int point, int &size, int &facesize)
facesize is the number of faces connected to the point, which might be different than size if some fa...
void SetPointList(Channel3DType channeltype, CPointList *newpoints, bool deletePrevious=true)
Attach a point list to the channel. newpoints is owned by the channel, and should not be deleted by t...
static CChannel * Create(Channel3DType type, ChannelID id=CHANNELID_UNDEFINED)
Allocates and creates a new channel. Use Delete if the channel is not attached to a CDependentChannel...
ChannelID GetChannelID() const
The channel ID allows to rely a specific material to a specific channel. This is not a GUID (differen...
ChannelConnectionInfo * GetChannelPointsConnectedToPoint(int point, int &size)
Return UVs connected to the point. size is the number of ChannelConnectionInfo * array entries for po...
void FreeExtra()
Release any extra memory attached to the channel.
CCustomData is a handly class for storing any kind of data.
Definition CustomData.h:106
This class contains an array of CChannel information which are associated to the object.
Definition DependentChannels.h:56
CFaceList is the common base class for a lot of different classes (C3DFaceList, CUVWFaceList....
Definition FaceList.h:179
CGeomInfo is an helper class oftenly required by different methods.
Definition GeomInfo.h:71
Definition InstanciatedObject.h:16
CPointList is the base class for different classes (C3DPointList, CUVWPointList......
Definition PointList.h:50
CPt base only contains some flags that are used by the derived class.
Definition Point.h:60
Definition XArchive.h:17
CXArray is an array of simple data information which does not requires to call a constructor / destru...
Definition XTemplate.h:34
Used by GetChannelPointsConnectedToPoint.
Definition Channel.h:77