-
-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* layer system, including save and load layer info from CJSON Signed-off-by: Marc Prat Masó <marc.prat.maso@estudiantat.upc.edu>
- Loading branch information
Showing
63 changed files
with
2,135 additions
and
555 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/****************************************************************************** | ||
This source file is part of the Avogadro project. | ||
This source code is released under the 3-Clause BSD License, (see "LICENSE"). | ||
******************************************************************************/ | ||
|
||
#include "layer.h" | ||
#include <cassert> | ||
|
||
namespace Avogadro { | ||
namespace Core { | ||
|
||
using std::swap; | ||
|
||
Layer::Layer() : m_activeLayer(0), m_maxLayer(0) {} | ||
|
||
void Layer::addAtom(size_t layer) | ||
{ | ||
addAtom(layer, m_atomAndLayers.size()); | ||
} | ||
|
||
void Layer::addAtom(size_t layer, Index atom) | ||
{ | ||
assert(layer <= m_maxLayer); | ||
if (atom == m_atomAndLayers.size()) { | ||
m_atomAndLayers.push_back(layer); | ||
} else if (atom > m_atomAndLayers.size()) { | ||
m_atomAndLayers.resize(layer + 1, MaxIndex); | ||
m_atomAndLayers[atom] = layer; | ||
} else { | ||
m_atomAndLayers[atom] = layer; | ||
} | ||
} | ||
|
||
void Layer::addAtomToActiveLayer(Index atom) | ||
{ | ||
addAtom(m_activeLayer, atom); | ||
} | ||
|
||
void Layer::setActiveLayer(size_t layer) | ||
{ | ||
assert(layer <= m_maxLayer + 1); | ||
m_activeLayer = layer; | ||
} | ||
|
||
void Layer::removeAtom(Index atom) | ||
{ | ||
m_atomAndLayers.swapAndPop(atom); | ||
} | ||
|
||
void Layer::addLayer() | ||
{ | ||
++m_maxLayer; | ||
} | ||
|
||
void Layer::addLayer(size_t layer) | ||
{ | ||
assert(layer <= m_maxLayer + 1); | ||
for (auto& atomLayer : m_atomAndLayers) { | ||
if (atomLayer >= layer) { | ||
++atomLayer; | ||
} | ||
} | ||
++m_maxLayer; | ||
} | ||
|
||
size_t Layer::getLayerID(Index atom) const | ||
{ | ||
if (atom >= m_atomAndLayers.size()) { | ||
return MaxIndex; | ||
} else { | ||
return m_atomAndLayers[atom]; | ||
} | ||
} | ||
|
||
void Layer::clear() | ||
{ | ||
m_atomAndLayers.clear(); | ||
m_activeLayer = m_maxLayer = 0; | ||
} | ||
|
||
size_t Layer::activeLayer() const | ||
{ | ||
return m_activeLayer; | ||
} | ||
|
||
size_t Layer::maxLayer() const | ||
{ | ||
return m_maxLayer; | ||
} | ||
|
||
size_t Layer::atomCount() const | ||
{ | ||
return m_atomAndLayers.size(); | ||
} | ||
|
||
void Layer::removeLayer(size_t layer) | ||
{ | ||
assert(layer <= m_maxLayer); | ||
if (m_maxLayer >= 1) { | ||
for (auto it = m_atomAndLayers.begin(); it != m_atomAndLayers.end();) { | ||
if (*it == layer) { | ||
it = m_atomAndLayers.erase(it); | ||
} else { | ||
if (*it > layer) { | ||
--(*it); | ||
} | ||
++it; | ||
} | ||
} | ||
--m_maxLayer; | ||
} | ||
} | ||
|
||
void Layer::swapLayer(Index a, Index b) | ||
{ | ||
swap(m_atomAndLayers[a], m_atomAndLayers[b]); | ||
} | ||
|
||
size_t Layer::layerCount() const | ||
{ | ||
return m_maxLayer + 1; | ||
} | ||
|
||
} // namespace Core | ||
} // namespace Avogadro |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/****************************************************************************** | ||
This source file is part of the Avogadro project. | ||
This source code is released under the 3-Clause BSD License, (see "LICENSE"). | ||
******************************************************************************/ | ||
|
||
#ifndef AVOGADRO_CORE_LAYER_H | ||
#define AVOGADRO_CORE_LAYER_H | ||
|
||
#include "avogadrocore.h" | ||
|
||
#include <avogadro/core/array.h> | ||
#include <avogadro/core/connectedgroup.h> | ||
|
||
namespace Avogadro { | ||
namespace Core { | ||
|
||
/** | ||
* @class Layer layer.h <avogadro/core/layer.h> | ||
* @brief The Layer class represents a relation one to one between atoms ID | ||
* and layer ID, and stores the unique active layer. | ||
* Layer's ID are consecutively and there can't be a ID bigger than @p | ||
* m_maxLayer. | ||
*/ | ||
class AVOGADROCORE_EXPORT Layer | ||
{ | ||
public: | ||
Layer(); | ||
|
||
// att atom to param layer | ||
void addAtom(size_t layer); | ||
void addAtom(size_t layer, Index atom); | ||
void addAtomToActiveLayer(Index atom); | ||
void removeAtom(Index atom); | ||
void removeLayer(size_t layer); | ||
|
||
/** @return the layer ID from the @p atom. */ | ||
size_t getLayerID(Index atom) const; | ||
/** @return the active Layer. */ | ||
size_t activeLayer() const; | ||
|
||
/** @return the maximum layer allowed. */ | ||
size_t maxLayer() const; | ||
|
||
/** @return the number of layers. */ | ||
size_t layerCount() const; | ||
|
||
/** @return The number of atoms. */ | ||
size_t atomCount() const; | ||
|
||
/** remove all IDs. */ | ||
void clear(); | ||
|
||
/** increase the maximum layer allowed .*/ | ||
void addLayer(); | ||
|
||
/** insert a layer at @p layer, equal or bigger previous layers will be | ||
* shifted. */ | ||
void addLayer(size_t layer); | ||
|
||
/** change @p m_activeLayer. */ | ||
void setActiveLayer(size_t layer); | ||
|
||
/** swap the layer ID from @p a and @p b. */ | ||
void swapLayer(Index a, Index b); | ||
|
||
private: | ||
Core::Array<size_t> m_atomAndLayers; | ||
size_t m_activeLayer; | ||
size_t m_maxLayer; | ||
}; | ||
|
||
} // namespace Core | ||
} // namespace Avogadro | ||
|
||
#endif |
Oops, something went wrong.