WDataSetPoints.h 6.37 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------

#ifndef WDATASETPOINTS_H
#define WDATASETPOINTS_H

#include <string>
#include <utility>
#include <vector>

#include <boost/shared_ptr.hpp>

#include "../common/WBoundingBox.h"
#include "WDataSet.h"

/**
 * Dataset to store a bunch of points without order or topology.
 */
class WDataSetPoints : public WDataSet // NOLINT
{
public:
    // some type alias for the used arrays.
    /**
     * Pointer to dataset.
     */
    typedef boost::shared_ptr< WDataSetPoints > SPtr;

    /**
     * Pointer to const dataset.
     */
    typedef boost::shared_ptr< const WDataSetPoints > ConstSPtr;

    /**
     * List of vertex coordinates in term of components of vertices.
     */
    typedef boost::shared_ptr< std::vector< float > > VertexArray;

    /**
     * Colors for each vertex in VertexArray.
     */
    typedef boost::shared_ptr< std::vector< float > > ColorArray;

    /**
     * Constructs a new set of points. If no color is specified, white is used for all points.
     *
     * \note the number of floats in vertices must be a multiple of 3
68
     * \note the number of floats in colors (if not NULL) must be vertices->size() / 3  times one of 1,3, or 4
69 70
     *
     * \param vertices the vertices of the points, stored in x1,y1,z1,x2,y2,z2, ..., xn,yn,zn scheme
Alexander Wiebel's avatar
Alexander Wiebel committed
71
     * \param colors the colors of each vertex. Can be NULL. Stored as R1,G1,B1,A1, ... Rn,Gn,Bn,An
72 73 74 75 76 77 78 79 80 81
     * \param boundingBox The bounding box of the points (first minimum, second maximum).
     */
    WDataSetPoints( VertexArray vertices, ColorArray colors,
                    WBoundingBox boundingBox );

    /**
     * Constructs a new set of points. The bounding box is calculated during construction. If no color is specified, white is used for all
     * points.
     *
     * \note the number of floats in vertices must be a multiple of 3
82
     * \note the number of floats in colors (if not NULL) must be vertices->size() / 3  times one of 1,3, or 4
83 84
     *
     * \param vertices the vertices of the points, stored in x1,y1,z1,x2,y2,z2, ..., xn,yn,zn scheme
Alexander Wiebel's avatar
Alexander Wiebel committed
85
     * \param colors the colors of each vertex. Can be NULL. Stored as R1,[G1,B1,[A1,]] ... Rn,[Gn,Bn,[An]]
86 87 88 89
     */
    WDataSetPoints( VertexArray vertices, ColorArray colors );

    /**
Alexander Wiebel's avatar
Alexander Wiebel committed
90
     * Constructs a new set of points. The constructed instance is empty.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
     */
    WDataSetPoints();

    /**
     * Destructor.
     */
    virtual ~WDataSetPoints();

    /**
     * Get number of points in this data set.
     *
     * \return number of points
     */
    size_t size() const;

    /**
     * Determines whether this dataset can be used as a texture.
     *
     * \return true if usable as texture.
     */
    virtual bool isTexture() const;

    /**
     * Gets the name of this prototype.
     *
     * \return the name.
     */
    virtual const std::string getName() const;

    /**
     * Gets the description for this prototype.
     *
     * \return the description
     */
    virtual const std::string getDescription() const;

    /**
     * Returns a prototype instantiated with the true type of the deriving class.
     *
     * \return the prototype.
     */
    static boost::shared_ptr< WPrototyped > getPrototype();

    /**
     * Getter for the point vertices
     * \return The vertices
     */
    VertexArray getVertices() const;

    /**
     * Getter for the point colors
     * \return The colors
     */
    ColorArray getColors() const;

    /**
     * Get the bounding box.
     * \return The bounding box of all points.
     */
    WBoundingBox getBoundingBox() const;

    /**
     * Query coordinates of a given point.
     *
     * \throw WOutOfBounds if invalid index is used.
     * \param pointIdx the point index.
     *
     * \return the coordinates
     */
    WPosition operator[]( const size_t pointIdx ) const;

162 163 164 165 166 167 168 169 170 171
    /**
     * Query coordinates of a given point.
     *
     * \throw WOutOfBounds if invalid index is used.
     * \param pointIdx the point index.
     *
     * \return the coordinates
     */
    WPosition getPosition( const size_t pointIdx ) const;

172 173 174 175 176 177 178 179 180 181
    /**
     * The color of a given point.
     *
     * \throw WOutOfBounds if invalid index is used.
     * \param pointIdx the point index.
     *
     * \return the color
     */
    WColor getColor( const size_t pointIdx ) const;

182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
    /**
     * Is this a valid point index?
     *
     * \param pointIdx the index to check
     *
     * \return true if yes.
     */
    bool isValidPointIdx( const size_t pointIdx ) const;

    /**
     * The type of colors we have for each point.
     */
    enum ColorType
    {
        GRAY = 1,
        RGB = 3,
        RGBA =4
    };

    /**
     * Check the type of color.
     *
     * \return the type
     */
    ColorType getColorType() const;
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
protected:
    /**
     * The prototype as singleton.
     */
    static boost::shared_ptr< WPrototyped > m_prototype;

private:
    /**
     * Point vector for all points
     */
    VertexArray m_vertices;

    /**
     * An array of the colors per vertex.
     */
    ColorArray m_colors;

224 225 226 227 228
    /**
     * Which colortype do we use in m_colors.
     */
    ColorType m_colorType;

229 230 231 232 233 234 235 236 237 238 239 240 241 242
    /**
     * Axis aligned bounding box for all point-vertices of this dataset.
     */
    WBoundingBox m_bb;

    /**
     * Initialize arrays and bbox if needed. Used during construction.
     *
     * \param calcBB if true, the bounding box is calculated
     */
    void init( bool calcBB = false );
};

#endif  // WDATASETPOINTS_H