View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0013819VTK(No Category)public2013-01-23 23:582014-10-03 04:50
ReporterTrevor 
Assigned ToJoachim Pouderoux 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version5.10.1 
Target Version6.2.0Fixed in Version 
Summary0013819: vtkHyperOctree->DeepCopy() provides shallow copy.
DescriptionAs reported on vtkUsers mailing list: http://www.vtk.org/pipermail/vtkusers/2013-January/127166.html [^]

The DeepCopy() method of vtkHyperOctree actually provides a shallow copy.
Steps To ReproduceThis can be seen in the following example:

/**
  @file File exhibiting possible error in VTK
  @author Trevor Irons
  @date 01/15/2013
  @version 0.0
 **/

#include <iostream>
#include "vtkHyperOctree.h"
#include "vtkHyperOctreeCursor.h"
#include "vtkDoubleArray.h"
#include "vtkDataSetAttributes.h"

using namespace std;
int main() {

    vtkHyperOctree* Octree1 = vtkHyperOctree::New();
        Octree1->SetDimension(3);
        Octree1->SetOrigin(0,0,0);


    cout << "Octree1 GetNum Leaves "<< Octree1->GetNumberOfLeaves() << std::endl;

    vtkHyperOctree* Octree2 = vtkHyperOctree::New();
        Octree1->SetDimension(3);
        Octree1->SetOrigin(0,0,0);
    cout << "Octree2 Num Leaves " << Octree2->GetNumberOfLeaves() << std::endl;

    // Now modify one of them
    vtkHyperOctreeCursor* Cursor = Octree1->NewCellCursor();
        Cursor->ToRoot();
        Octree1->SubdivideLeaf(Cursor);

    // set some leaf data
    vtkDoubleArray *leafData = vtkDoubleArray::New();
    for (int i=0; i<8; ++i) {
        leafData->InsertNextTuple1(i);
    }
    leafData->SetName("da leaf data");
    Octree1->GetLeafData()->SetScalars( leafData );

    // copy
    Octree2->DeepCopy(Octree1);

    cout << "After Subdivide Octree1 GetNum Leaves = " << Octree1->GetNumberOfLeaves() << std::endl;
    cout << "Octree2 Num Leaves (expect changed) = " << Octree2->GetNumberOfLeaves() << std::endl;

    // Leaf Data
    cout << Octree1->GetLeafData()->GetScalars() << std::endl;
    cout << Octree2->GetLeafData()->GetScalars() << std::endl;
    for (int i=0; i<8; ++i) {
        cout << Octree1->GetLeafData()->GetScalars()->GetTuple1(i) << std::endl;
        cout << Octree2->GetLeafData()->GetScalars()->GetTuple1(i) << std::endl;
    }

    // muck with Octree1
    Cursor->ToRoot();
    for (int i=0; i<8; ++i) {
        Cursor->ToChild(i);
        Octree1->SubdivideLeaf(Cursor);
        Cursor->ToParent();
    }

    cout << "After Subdivide Octree1 GetNum Leaves = " << Octree1->GetNumberOfLeaves() << std::endl;
    cout << "Octree2 Num Leaves (expect NOT changed) = " << Octree2->GetNumberOfLeaves() << std::endl;


    Octree1->Delete();
    Octree2->Delete();
    Cursor->Delete();
    leafData->Delete();
}

It is clear that DeepCopy is providing a shallow copy.
TagsNo tags attached.
ProjectTBD
Typeincorrect functionality
Attached Files

 Relationships

  Notes
(0033470)
Joachim Pouderoux (developer)
2014-10-02 11:40

Change I393b4447: Fix vtkHyperOctree copy functions.
http://review.source.kitware.com/#/c/17328/ [^]

DeepCopy used to perform a ShallowCopy instead.
A new DeepCopy operator has been added to the internal structure
in order to copy the tree correctly.

Change-Id: I393b4447b2f1014604e9fdbd6e7286f8ec563701

------------------------------
The new output of the test is:
----------------

Octree1 GetNum Leaves 1
Octree2 Num Leaves 1
After Subdivide Octree1 GetNum Leaves = 8
Octree2 Num Leaves (expect changed) = 8
0000000000226400
0000000000226780
0
0
1
1
2
2
3
3
4
4
5
5
6
6
7
7
After Subdivide Octree1 GetNum Leaves = 64
Octree2 Num Leaves (expect NOT changed) = 8
(0033564)
Joachim Pouderoux (developer)
2014-10-03 04:50

From Trevor:
"
Addresses/resolves my particular use-case. Thank you for this fix.
"
Topic merged in master.

 Issue History
Date Modified Username Field Change
2013-01-23 23:58 Trevor New Issue
2014-10-02 10:02 Berk Geveci Assigned To => Joachim Pouderoux
2014-10-02 11:40 Joachim Pouderoux Note Added: 0033470
2014-10-02 11:43 Joachim Pouderoux Status backlog => active development
2014-10-02 11:44 Joachim Pouderoux Description Updated
2014-10-02 11:44 Joachim Pouderoux Steps to Reproduce Updated
2014-10-03 04:49 Joachim Pouderoux Reproducibility have not tried => always
2014-10-03 04:49 Joachim Pouderoux Status active development => gerrit review
2014-10-03 04:49 Joachim Pouderoux Target Version => 6.2.0
2014-10-03 04:50 Joachim Pouderoux Note Added: 0033564
2014-10-03 04:50 Joachim Pouderoux Status gerrit review => closed
2014-10-03 04:50 Joachim Pouderoux Resolution open => fixed


Copyright © 2000 - 2018 MantisBT Team