pointsCentroid[2] /= sizeLstX;
if ((bbGetInputCloseSurface()==true) && (lstIndexs.size()>=2) )
- {
+ {
+ //check if initial and end points are the same in all splines (splines are in line shape and not U shape)
+ //to not apply changes because clean polydata will take care of it.
+ int count = 0;
+ bool differentPoints = false;
+ for(i=0; i < lstIndexs.size() && !differentPoints;i++){
+ bool sameStart = lstX[count] != lstX[count+lstIndexs[i]-1] && lstY[count] != lstY[count+lstIndexs[i]-1] && lstZ[count] != lstZ[count+lstIndexs[i]-1];
+ bool sameEnd = lstX[count] != lstX[count+lstIndexs[i]-1] && lstY[count] != lstY[count+lstIndexs[i]-1] && lstZ[count] != lstZ[count+lstIndexs[i]-1];
+ if(!(sameStart && sameEnd)) differentPoints = true;
+ count += lstIndexs[i];
+ }
//Correct surface normals if needed
- double pointSurf1[3], pointSurf2[3], pointSurf3[3];
- double vect1[3], vect2[3];
- double surfNormal[3], vectorCenter[3];
- double dotNormalSurf = 0;
- for(int pIndex = 0; pIndex < lstIndexs[0]-1; pIndex++)
- {
- pointSurf1[0] = lstX[pIndex];
- pointSurf1[1] = lstY[pIndex];
- pointSurf1[2] = lstZ[pIndex];
- vtkMath::Subtract(pointsCentroid, pointSurf1, vectorCenter);
- pointSurf2[0] = lstX[pIndex+lstIndexs[1]];
- pointSurf2[1] = lstY[pIndex+lstIndexs[1]];
- pointSurf2[2] = lstZ[pIndex+lstIndexs[1]];
- pointSurf3[0] = lstX[pIndex+1];
- pointSurf3[1] = lstY[pIndex+1];
- pointSurf3[2] = lstZ[pIndex+1];
- vtkMath::Subtract(pointSurf2, pointSurf1, vect1);
- vtkMath::Subtract(pointSurf3, pointSurf1, vect2);
- vtkMath::Cross(vect1, vect2, surfNormal);
- dotNormalSurf += vtkMath::Dot(surfNormal, vectorCenter);
- } // for pIndex
- if(dotNormalSurf > 0){
- points->Delete();
- points = vtkPoints::New();
- for(int splineI = 0; splineI < lstIndexs.size(); splineI++){
- for (i=lstIndexs[splineI]-1; i >= 0;i--)
- {
- points->InsertNextPoint(lstX[splineI*lstIndexs[0]+i],lstY[splineI*lstIndexs[0]+i],lstZ[splineI*lstIndexs[0]+i]);
- } // for i
- } // for splineI
- } // if dotNormalSurf
+ if(differentPoints)
+ {
+ double pointSurf1[3], pointSurf2[3], pointSurf3[3];
+ double vect1[3], vect2[3];
+ double surfNormal[3], vectorCenter[3];
+ double dotNormalSurf = 0;
+ for(int pIndex = 0; pIndex < lstIndexs[0]-1; pIndex++)
+ {
+ pointSurf1[0] = lstX[pIndex];
+ pointSurf1[1] = lstY[pIndex];
+ pointSurf1[2] = lstZ[pIndex];
+ vtkMath::Subtract(pointsCentroid, pointSurf1, vectorCenter);
+ pointSurf2[0] = lstX[pIndex+lstIndexs[1]];
+ pointSurf2[1] = lstY[pIndex+lstIndexs[1]];
+ pointSurf2[2] = lstZ[pIndex+lstIndexs[1]];
+ pointSurf3[0] = lstX[pIndex+1];
+ pointSurf3[1] = lstY[pIndex+1];
+ pointSurf3[2] = lstZ[pIndex+1];
+ vtkMath::Subtract(pointSurf2, pointSurf1, vect1);
+ vtkMath::Subtract(pointSurf3, pointSurf1, vect2);
+ vtkMath::Cross(vect1, vect2, surfNormal);
+ dotNormalSurf += vtkMath::Dot(surfNormal, vectorCenter);
+ } // for pIndex
+
+ if(dotNormalSurf > 0){
+ points->Delete();
+ points = vtkPoints::New();
+ for(int splineI = 0; splineI < lstIndexs.size(); splineI++){
+ for (i=lstIndexs[splineI]-1; i >= 0;i--)
+ {
+ points->InsertNextPoint(lstX[splineI*lstIndexs[0]+i],lstY[splineI*lstIndexs[0]+i],lstZ[splineI*lstIndexs[0]+i]);
+ } // for i
+ } // for splineI
+ } // if dotNormalSurf
+ }// if differentPoints
}
//
void HistoryHandler<T>::Save(T* state)
{
undoStack.push_back(state);
+ if(undoStack.size() > maxElements)
+ {
+ delete undoStack.front();
+ undoStack.pop_front();
+ }
if(!redoStack.empty())
{
for (T* element : redoStack)
template <class T>
T* HistoryHandler<T>::GetPrevious()
{
- if(!undoStack.empty()){
+ if(!undoStack.empty())
+ {
return undoStack.back();
}
return NULL;
template <class T>
T* HistoryHandler<T>::GetNext()
{
- if(!redoStack.empty()){
+ if(!redoStack.empty())
+ {
return redoStack.back();
}
return NULL;
MeshModel::MeshModel(vtkPolyData* mesh, int id)
{
- if(mesh != NULL){
+ if(mesh != NULL)
+ {
_meshBase = vtkPolyData::New();//mesh;
_meshBase->DeepCopy(mesh);
_meshTemp = vtkPolyData::New();
_name = "mesh-" + std::to_string(meshModel->GetId());
}
-MeshModel::~MeshModel(){
- if(_meshBase != NULL){
+MeshModel::~MeshModel()
+{
+ if(_meshBase != NULL)
+ {
_meshBase->Delete();
}
- if(_meshTemp != NULL){
+ if(_meshTemp != NULL)
+ {
_meshTemp->Delete();
}
}
{
if (mesh!=NULL)
{
- if(_meshBase != NULL){
+ if(_meshBase != NULL)
+ {
_meshBase->Delete();
}
_meshBase = vtkPolyData::New();
{
currentMesh = 0;
meshId = 0;
- history = new HistoryHandler<ManagerState>(20);
+ history = new HistoryHandler<ManagerState>(15);
lastModified = 0;
}
void MeshManagerModel::AddMesh_(vtkPolyData* mesh)
{
- if(mesh != NULL){
+ if(mesh != NULL)
+ {
_meshes.push_back(std::make_shared<MeshModel>(mesh, meshId));
meshId++;
- }
- else{
+ }else{
printf("PG MeshManagerModel::AddMesh Mesh is null \n");
}
}
void MeshManagerModel::SelectMesh(int i)
{
- if(i >= 0 && i < _meshes.size()){
+ if(i >= 0 && i < _meshes.size())
+ {
int prevCurrent = currentMesh;
currentMesh = i;
- if(prevCurrent != i){
+ if(prevCurrent != i)
+ {
RefreshOutputs(true);
}
}
void MeshManagerModel::SelectMeshByName(std::string meshName)
{
- if(!_meshes.empty()){
+ if(!_meshes.empty())
+ {
bool found = false;
for(int i = 0; i < _meshes.size() && !found; i++){
- if(_meshes.at(i)->GetName() == meshName){
+ if(_meshes.at(i)->GetName() == meshName)
+ {
found = true;
SelectMesh(i);
}
void MeshManagerModel::DeleteMesh_(int position)
{
- if(position >= 0 && position < _meshes.size()){
+ if(position >= 0 && position < _meshes.size())
+ {
_meshes.erase(_meshes.begin() + position);
currentMesh = currentMesh + (position <= currentMesh?-1:0);
- if(currentMesh < 0){
+ if(currentMesh < 0)
+ {
currentMesh = 0;
}
}
void MeshManagerModel::DeleteMeshByName(std::string meshName)
{
- if(!_meshes.empty()){
+ if(!_meshes.empty())
+ {
bool found = false;
for(int i = 0; i < _meshes.size() && !found; i++){
- if(_meshes.at(i)->GetName() == meshName){
+ if(_meshes.at(i)->GetName() == meshName)
+ {
found = true;
DeleteMesh_(i);
RefreshOutputs(true);
void MeshManagerModel::DeleteCurrentMesh()
{
- if(!_meshes.empty()){
+ if(!_meshes.empty())
+ {
Save();
DeleteMesh_(currentMesh);
lastModified = currentMesh;
void MeshManagerModel::NextMesh()
{
currentMesh++;
- if(currentMesh >= _meshes.size()){
+ if(currentMesh >= _meshes.size())
+ {
currentMesh = _meshes.size()-1;
}
RefreshOutputs(true);
void MeshManagerModel::PreviousMesh()
{
currentMesh--;
- if(currentMesh < 0){
+ if(currentMesh < 0)
+ {
currentMesh = 0;
}
RefreshOutputs(true);
vtkPolyData* MeshManagerModel::GetMeshBase()
{
- if(!_meshes.empty()){
+ if(!_meshes.empty())
+ {
return _meshes.at(currentMesh)->GetMeshBase();
}
else{
vtkPolyData* MeshManagerModel::GetMeshTemp()
{
- if(!_meshes.empty()){
+ if(!_meshes.empty())
+ {
return _meshes.at(currentMesh)->GetMeshTemp();
}
else{
void MeshManagerModel::SetMeshBase(vtkPolyData* mesh)
{
- if(!_meshes.empty()){
+ if(!_meshes.empty())
+ {
Save();
_meshes.at(currentMesh) = std::make_shared<MeshModel>(_meshes.at(currentMesh).get());
_meshes.at(currentMesh)->SetMeshBase(mesh);
void MeshManagerModel::Undo()
{
- if(history->UndoSize() > 0){
+ if(history->UndoSize() > 0)
+ {
RestoreState(history->Undo(new ManagerState(_meshes, meshId, lastModified)));
RefreshOutputs(true);
}
meshId = state->GetMeshId();
currentMesh = state->GetModifiedPos();
lastModified = state->GetModifiedPos();
-// cout << "PG MeshManagerModel::RestoreState currentMesh: " << currentMesh << endl;
}
}
MeshManagerModel::ManagerState::~ManagerState()
{
+ savedMeshes.clear();
}
std::vector<std::shared_ptr<MeshModel>>& MeshManagerModel::ManagerState::GetMeshes()