Avogadro
1.1.0
|
00001 /********************************************************************** 00002 Cube - Primitive class to encapsulate volumetric data 00003 00004 Copyright (c) 2008-2009 Marcus D. Hanwell 00005 Copyright (c) 2009 Geoff Hutchison 00006 00007 This file is part of the Avogadro molecular editor project. 00008 For more information, see <http://avogadro.openmolecules.net/> 00009 00010 Avogadro is free software; you can redistribute it and/or modify 00011 it under the terms of the GNU General Public License as published by 00012 the Free Software Foundation; either version 2 of the License, or 00013 (at your option) any later version. 00014 00015 Avogadro is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 along with this program; if not, write to the Free Software 00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00023 02110-1301, USA. 00024 **********************************************************************/ 00025 00026 #ifndef CUBE_H 00027 #define CUBE_H 00028 00029 #include <avogadro/primitive.h> 00030 00031 #include <vector> 00032 00033 // Forward declarations 00034 class QReadWriteLock; 00035 00036 namespace Avogadro { 00037 00049 class Molecule; 00050 00051 class CubePrivate; 00052 class A_EXPORT Cube : public Primitive 00053 { 00054 Q_OBJECT 00055 00056 public: 00057 Cube(QObject *parent=0); 00058 ~Cube(); 00059 00063 enum Type{ 00064 VdW, 00065 ESP, 00066 ElectronDensity, 00067 MO, 00068 FromFile, 00069 None 00070 }; 00071 00075 Eigen::Vector3d min() const { return m_min; } 00076 00080 Eigen::Vector3d max() const { return m_max; } 00081 00085 Eigen::Vector3d spacing() const { return m_spacing; } 00086 00090 Eigen::Vector3i dimensions() const { return m_points; } 00091 00098 bool setLimits(const Eigen::Vector3d &min, const Eigen::Vector3d &max, 00099 const Eigen::Vector3i &points); 00100 00107 bool setLimits(const Eigen::Vector3d &min, const Eigen::Vector3d &max, 00108 double spacing); 00109 00116 bool setLimits(const Eigen::Vector3d &min, const Eigen::Vector3i &dim, 00117 double spacing); 00118 00123 bool setLimits(const Cube &cube); 00124 00131 bool setLimits(const Molecule *mol, double spacing, double padding); 00132 00136 std::vector<double> * data(); 00137 00141 bool setData(const std::vector<double> &values); 00142 00146 bool addData(const std::vector<double> &values); 00147 00152 unsigned int closestIndex(const Eigen::Vector3d &pos) const; 00153 00160 Eigen::Vector3i indexVector(const Eigen::Vector3d &pos) const; 00161 00166 Eigen::Vector3d position(unsigned int index) const; 00167 00172 double value(int i, int j, int k) const; 00173 00178 double value(const Eigen::Vector3i &pos) const; 00179 00187 float valuef(const Eigen::Vector3f &pos) const; 00188 00196 double value(const Eigen::Vector3d &pos) const; 00197 00205 bool setValue(int i, int j, int k, double value); 00206 00211 bool setValue(unsigned int i, double value); 00212 00216 double minValue() const { return m_minValue; } 00217 00221 double maxValue() const { return m_maxValue; } 00222 00223 void setName(QString name) { m_name = name; } 00224 QString name() const { return m_name; } 00225 00226 void setCubeType(Type type) { m_cubeType = type; } 00227 Type cubeType() { return m_cubeType; } 00228 00232 QReadWriteLock *lock() const; 00233 00234 friend class Molecule; 00235 00236 protected: 00237 std::vector<double> m_data; 00238 Eigen::Vector3d m_min, m_max, m_spacing; 00239 Eigen::Vector3i m_points; 00240 double m_minValue, m_maxValue; 00241 QString m_name; 00242 Type m_cubeType; 00243 QReadWriteLock *m_lock; 00244 Q_DECLARE_PRIVATE(Cube) 00245 }; 00246 00247 inline bool Cube::setValue(unsigned int i, double value) 00248 { 00249 if (i < m_data.size()) { 00250 m_data[i] = value; 00251 if (value > m_maxValue) m_maxValue = value; 00252 if (value < m_minValue) m_minValue = value; 00253 return true; 00254 } 00255 else 00256 return false; 00257 } 00258 00259 } // End namespace Avogadro 00260 00261 #endif