FilePTS.hh 8.54 KB
Newer Older
1 2 3 4 5
//================================================================
//
/*===========================================================================*\
*                                                                            *
*                              OpenFlipper                                   *
Martin Schultz's avatar
Martin Schultz committed
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
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
41 42 43
*                                                                            *
\*===========================================================================*/

Jan Möbius's avatar
Jan Möbius committed
44

45 46 47 48 49 50 51 52 53 54


//================================================================
//
//  CLASS FilePTSPlugin
//
//    This class is the base class for loading and saving (reading/writing) SplatCloud objects from/to disc.
//
//================================================================

Jan's avatar
Jan committed
55
#pragma once
56 57 58 59 60 61 62 63 64 65 66 67 68


//== INCLUDES ====================================================


#include <QObject>

#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/FileInterface.hh>
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/ScriptInterface.hh>
#include <OpenFlipper/BasePlugin/RPCInterface.hh>
69
#include <OpenFlipper/BasePlugin/AboutInfoInterface.hh>
70 71 72 73

#include <OpenFlipper/common/Types.hh>

#include <ObjectTypes/SplatCloud/SplatCloud.hh>
Jan's avatar
Jan committed
74
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
Jan's avatar
Jan committed
75
#include <ObjectTypes/PolyMesh/PolyMesh.hh>
Jan's avatar
Jan committed
76 77 78 79 80 81 82

#include <QComboBox>
#include <QCheckBox>
#include <QLayout>
#include <QHBoxLayout>
#include <QGroupBox>
#include <QPushButton>
83

84
#include "ui_ptsLoadWidget.h"
85 86 87

//== CLASS DEFINITION ============================================

Jan's avatar
Jan committed
88 89 90 91 92 93 94
class AdaptorBase {

public:
    virtual void clear() = 0;
    virtual void add_point(ACG::Vec3d  _point) = 0;
    virtual void setNormal(ACG::Vec3d _normal) = 0;
    virtual void setColor(ACG::Vec4f  _color) = 0;
Jan Möbius's avatar
Jan Möbius committed
95
    virtual void setColor(ACG::Vec3uc  _color) = 0;
96 97
    virtual void setPointSize(float _size ) = 0;
    virtual void setIndex(int _index ) = 0;
Jan's avatar
Jan committed
98 99 100

    virtual void request_vertex_normals() = 0;
    virtual void request_vertex_colors() = 0;
Jan's avatar
Jan committed
101 102
    virtual void request_point_sizes() = 0;
    virtual void request_indices() = 0;
Jan's avatar
Jan committed
103

104
    virtual void reserve(size_t _size) = 0;
105 106

    virtual DataType adaptorType() = 0;
Jan's avatar
Jan committed
107 108
};

109 110 111 112 113 114 115 116
class ptsLoadWiget : public QWidget, public Ui::ptsLoadWidget
{
  Q_OBJECT

  public:
    explicit ptsLoadWiget(QWidget *parent = 0) : QWidget(parent) {     setupUi(this);  };
};

117 118
/// Enum defining read Order
enum ReadObject{ PointPos,PointNormal,PointColor,PointSize,PointIndex };
119

120
class FilePTSPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInterface, LoggingInterface, ScriptInterface, RPCInterface, AboutInfoInterface
121 122
{
  Q_OBJECT
123 124 125 126 127 128 129
  Q_INTERFACES( FileInterface      )
  Q_INTERFACES( LoadSaveInterface  )
  Q_INTERFACES( LoggingInterface   )
  Q_INTERFACES( BaseInterface      )
  Q_INTERFACES( ScriptInterface    )
  Q_INTERFACES( RPCInterface       )
  Q_INTERFACES( AboutInfoInterface )
Jan's avatar
Jan committed
130

Matthias Möller's avatar
Matthias Möller committed
131
  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-FilePTS")
Jan's avatar
Jan committed
132

133 134 135 136 137 138 139 140 141 142 143 144 145 146
signals:

  // -- File Interface --
  void openedFile( int _objectId );

  // -- LoadSave Interface --
  void addEmptyObject( DataType _type, int &_objectId );
  void deleteObject ( int _objectId );
  void updatedObject( int _objectId, const UpdateType &_type );

  //-- Logging Interface --
  void log(                QString _message );
  void log( Logtype _type, QString _message );

147 148 149
  //-- AboutInfoInterface --
  void addAboutInfo(QString _text, QString _tabName);

150 151 152
private slots:

  // -- Base Interface --
153
  void initializePlugin();
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
  void noguiSupported() { }

public:

  // standard constructor/destructor
  FilePTSPlugin();
  ~FilePTSPlugin() { }

  //-- Base Interface --
  QString name()         { return QString(    "FilePTS"                            ); }
  QString description( ) { return QString( tr("Load/Save SplatCloud format files") ); }

  // -- File Interface --
  DataType supportedType() { return DATA_SPLATCLOUD; }

  // -- File Interface --
  QString getSaveFilters() { return QString( tr("SplatCloud format files ( *.pts *.bin )") ); }
  QString getLoadFilters() { return QString( tr("SplatCloud format files ( *.pts *.bin )") ); }
  QWidget *saveOptionsWidget( QString /*_currentFilter*/ );
  QWidget *loadOptionsWidget( QString /*_currentFilter*/ );

public slots:

  // -- Base Interface --
  QString version() { return QString( "1.0" ); }

  // -- File Interface --
  int  loadObject(                QString _filename );
  bool saveObject( int _objectId, QString _filename );

private:

  // read binary/text file from disc to scenegraph node
  bool readBinaryFile( const char *_filename, SplatCloud &_splatCloud ) /*const*/;

Jan's avatar
Jan committed
189
  bool readTextFile  ( const char *_filename, AdaptorBase& _adaptor );
Jan's avatar
Jan committed
190

191 192 193 194
  // write binary/text file from scenegraph node to disc
  bool writeBinaryFile( const char *_filename, const SplatCloudNode *_splatCloudNode ) /*const*/;
  bool writeTextFile  ( const char *_filename, const SplatCloudNode *_splatCloudNode ) /*const*/;

195 196 197
  // read and decompress a binary chunk from file stream (snappy compression)
  bool readCompressedBinaryChunk( FILE* _file, size_t _compressedSize, char* _dst );

198 199
  // Get a read Object Order from ui
  std::vector<ReadObject> getReadObjectOrder();
200

201
  // widgets
202
  ptsLoadWiget *loadOptions_;
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
  QWidget *saveOptions_;

  // options in the saving menu
  QCheckBox *saveBinaryFile_;
  QCheckBox *saveNormals_;
  QCheckBox *savePointsizes_;
  QCheckBox *saveColors_;
  QComboBox *saveColorRange_;
  QCheckBox *saveIndices_;

  // buttons
  QPushButton *saveMakeDefaultButton_;

private slots:

  // slots called when the Load/Save colors checkbox or binaryfile checkbox was clicked
  void slotUpdateSaveColorRange();

  // slots called when user wants to save the given Load/Save Options as default
  void slotLoadMakeDefaultButtonClicked();
  void slotSaveMakeDefaultButtonClicked();
};


//================================================================