# After testing, it was found that updating only the vtkMapper of vtkActor itself without replacing the new vtkPolyDataMapper object after editing vtkPoints has no effect

**URL:** https://discourse.vtk.org/t/after-testing-it-was-found-that-updating-only-the-vtkmapper-of-vtkactor-itself-without-replacing-the-new-vtkpolydatamapper-object-after-editing-vtkpoints-has-no-effect/15014
**Category:** Support
**Created:** [December 13, 2024, 6:00am UTC](https://discourse.vtk.org/t/after-testing-it-was-found-that-updating-only-the-vtkmapper-of-vtkactor-itself-without-replacing-the-new-vtkpolydatamapper-object-after-editing-vtkpoints-has-no-effect/15014 "2024-12-13T06:00:28Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![jiajiadelequ](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jiajiadelequ/32/8738_2.png) [@jiajiadelequ](https://discourse.vtk.org/u/jiajiadelequ)
#### Post date: [December 13, 2024, 6:00am UTC](https://discourse.vtk.org/t/after-testing-it-was-found-that-updating-only-the-vtkmapper-of-vtkactor-itself-without-replacing-the-new-vtkpolydatamapper-object-after-editing-vtkpoints-has-no-effect/15014/1 "2024-12-13T06:00:28Z")

</div>

void CustomVtkInteractorStyleTapeMeasure::StartRotate() {  
Superclass::StartRotate();

```
vtkRenderer* renderer = this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer();
this->Interactor->GetRenderWindow()->AddRenderer(renderer);

int* clickPos = this->GetInteractor()->GetEventPosition();
vtkAbstractPicker* abstractPicker = this->GetInteractor()->GetPicker();
int pickCode = abstractPicker->Pick(clickPos[0], clickPos[1], 0, renderer);
if (mPicked = pickCode != 0) {
    double picked[3];
    abstractPicker->GetPickPosition(picked);

    vtkNew<vtkActor> vtkPointDisplay;
    vtkNew<vtkSphereSource> sphereSource;
    sphereSource->Update();
    vtkNew<vtkPolyDataMapper> sphereMapper;
    sphereMapper->SetInputData(sphereSource->GetOutput());
    vtkPointDisplay->SetMapper(sphereMapper);
    vtkPointDisplay->SetPosition(picked);
    vtkPointDisplay->SetScale(5,5,5);
    mPointsDisplays->AddItem(vtkPointDisplay);
    renderer->AddActor(vtkPointDisplay);

    mLastPos[0] = picked[0];
    mLastPos[1] = picked[1];
    mLastPos[2] = picked[2];

    if (mPointCount == 0) {
        mPoints->InsertNextPoint(picked);
        mPointCount++;
    }
    else
    {
        mPoints->SetPoint(mPointCount-1, picked);
    }
    mPoints->InsertNextPoint(picked);
    mPointCount++;
    mPolyLine->GetPointIds()->SetNumberOfIds(mPointCount);;// 设置点数
    for (size_t i = 0; i < mPointCount; i++)
    {
        mPolyLine->GetPointIds()->SetId(i, i);
        //double* point = mPoints->GetPoint(i);
        //logger::log("(%f,%f,%f)", point[0], point[1], point[2]);
    }

   
    mCells->InsertNextCell(mPolyLine);
    mCells->Modified();

    mPolyData->SetPoints(mPoints);
    mPolyData->SetLines(mCells);
    mPolyData->Modified();

    //mPolyDataMapper->SetInputData(mPolyData); It didn't have any effect
    //mPolyDataMapper->Update();
    //mPolyDataMapper->Modified();
 
    //mActor->SetMapper(mPolyDataMapper); 

    vtkNew<vtkPolyDataMapper> mapper;
    mapper->SetInputData(mPolyData);
    mActor->SetMapper(mapper);
    mActor->Modified();
    
    
    Interactor->Render();

}

```

}

After testing, it was found that updating only the vtkMapper of vtkActor itself without replacing the new vtkPolyDataMapper object after editing vtkPoints has no effect

---

<div class="post-metadata">

### Author: ![jiajiadelequ](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jiajiadelequ/32/8738_2.png) [@jiajiadelequ](https://discourse.vtk.org/u/jiajiadelequ)
#### Post date: [December 13, 2024, 6:05am UTC](https://discourse.vtk.org/t/after-testing-it-was-found-that-updating-only-the-vtkmapper-of-vtkactor-itself-without-replacing-the-new-vtkpolydatamapper-object-after-editing-vtkpoints-has-no-effect/15014/2 "2024-12-13T06:05:19Z")

</div>

Uploading: CustomVtkInteractorStyleTapeMeasure.cpp…

---

<div class="post-metadata">

### Author: ![jiajiadelequ](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jiajiadelequ/32/8738_2.png) [@jiajiadelequ](https://discourse.vtk.org/u/jiajiadelequ)
#### Post date: [December 13, 2024, 6:05am UTC](https://discourse.vtk.org/t/after-testing-it-was-found-that-updating-only-the-vtkmapper-of-vtkactor-itself-without-replacing-the-new-vtkpolydatamapper-object-after-editing-vtkpoints-has-no-effect/15014/3 "2024-12-13T06:05:59Z")

</div>

[CustomVtkInteractorStyleTapeMeasure.h](https://discourse.vtk.org/uploads/short-url/15L4cwCGd0iFVK5qAo86AfzDW74.h) (1.4 KB)

---

<div class="post-metadata">

### Author: ![jiajiadelequ](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jiajiadelequ/32/8738_2.png) [@jiajiadelequ](https://discourse.vtk.org/u/jiajiadelequ)
#### Post date: [December 13, 2024, 6:06am UTC](https://discourse.vtk.org/t/after-testing-it-was-found-that-updating-only-the-vtkmapper-of-vtkactor-itself-without-replacing-the-new-vtkpolydatamapper-object-after-editing-vtkpoints-has-no-effect/15014/4 "2024-12-13T06:06:47Z")

</div>

[CustomVtkInteractorStyleTapeMeasure.cpp](https://discourse.vtk.org/uploads/short-url/sODtS8UVVbomkPNbRbM4tW2bQ7G.cpp) (5.5 KB)

---

<div class="post-metadata">

### Author: ![jiajiadelequ](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jiajiadelequ/32/8738_2.png) [@jiajiadelequ](https://discourse.vtk.org/u/jiajiadelequ)
#### Post date: [December 13, 2024, 6:20am UTC](https://discourse.vtk.org/t/after-testing-it-was-found-that-updating-only-the-vtkmapper-of-vtkactor-itself-without-replacing-the-new-vtkpolydatamapper-object-after-editing-vtkpoints-has-no-effect/15014/5 "2024-12-13T06:20:48Z")

</div>

it‘s use the vtkMapper of vtkActor itself

---

<div class="post-metadata">

### Author: ![jiajiadelequ](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jiajiadelequ/32/8738_2.png) [@jiajiadelequ](https://discourse.vtk.org/u/jiajiadelequ)
#### Post date: [December 13, 2024, 6:21am UTC](https://discourse.vtk.org/t/after-testing-it-was-found-that-updating-only-the-vtkmapper-of-vtkactor-itself-without-replacing-the-new-vtkpolydatamapper-object-after-editing-vtkpoints-has-no-effect/15014/6 "2024-12-13T06:21:51Z")

</div>

it’s use the new vtkPolyDataMapper object

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [December 13, 2024, 10:46pm UTC](https://discourse.vtk.org/t/after-testing-it-was-found-that-updating-only-the-vtkmapper-of-vtkactor-itself-without-replacing-the-new-vtkpolydatamapper-object-after-editing-vtkpoints-has-no-effect/15014/7 "2024-12-13T22:46:02Z")

</div>

Altering a few points does not trigger Modified event in the polydata. This is not a bug but a feature: it allows making changes in bulk without triggering rendering or processing. When you are done with the updates you call `Modified()` at the appropriate level(s).

---

<div class="post-metadata">

### Author: ![jiajiadelequ](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jiajiadelequ/32/8738_2.png) [@jiajiadelequ](https://discourse.vtk.org/u/jiajiadelequ)
#### Post date: [December 16, 2024, 1:47am UTC](https://discourse.vtk.org/t/after-testing-it-was-found-that-updating-only-the-vtkmapper-of-vtkactor-itself-without-replacing-the-new-vtkpolydatamapper-object-after-editing-vtkpoints-has-no-effect/15014/9 "2024-12-16T01:47:46Z")

</div>

I’m really sorry, maybe I didn’t understand your description. I have tried using the modified () function of vtkPolyData, which is useful, but it still doesn’t work if I don’t replace the brand new vtkPolyDataMapper object. After replacing it, I can get the correct effect. If possible, could you provide specific code as a hint

//mPolyDataMapper-\>SetInputData(mPolyData); It didn’t have any effect

//mPolyDataMapper-\>Update();

//mPolyDataMapper-\>Modified();

//mActor-\>SetMapper(mPolyDataMapper);

vtkNew mapper;

mapper-\>SetInputData(mPolyData);

mActor-\>SetMapper(mapper);

mActor-\>Modified();

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [December 16, 2024, 2:00am UTC](https://discourse.vtk.org/t/after-testing-it-was-found-that-updating-only-the-vtkmapper-of-vtkactor-itself-without-replacing-the-new-vtkpolydatamapper-object-after-editing-vtkpoints-has-no-effect/15014/10 "2024-12-16T02:00:39Z")

</div>

When you are done modifying your points then mark the points object (`mPoints`) as modified, not the polydata object (`mPolyData`).

---

<div class="post-metadata">

### Author: ![jiajiadelequ](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jiajiadelequ/32/8738_2.png) [@jiajiadelequ](https://discourse.vtk.org/u/jiajiadelequ)
#### Post date: [December 16, 2024, 2:22am UTC](https://discourse.vtk.org/t/after-testing-it-was-found-that-updating-only-the-vtkmapper-of-vtkactor-itself-without-replacing-the-new-vtkpolydatamapper-object-after-editing-vtkpoints-has-no-effect/15014/11 "2024-12-16T02:22:48Z")

</div>

Thank you, I succeeded. I am truly grateful
