[vtkusers] Changing Cell Color After picking

Dominik Szczerba domi at vision.ee.ethz.ch
Mon Jan 8 04:30:54 EST 2007


You define how the scalars are mapped (or even enabled or not) in a
vtkMapper. There is also a scalar range you have to set to correspond to
your data and/or what you want to see. See the numerous examples about a
vtkMapper.
--DS

Ricardo Seco VTK wrote:
> Could you please be more specific?
> 
> Thanks
> Ricardo Seco
> Dominik Szczerba escreveu:
>> enable coloring the dataset with a scalar, set the right one
>> --ds
>>
>> Ricardo Seco VTK wrote:
>>  
>>> Still no results :(
>>>
>>> Ricardo Seco
>>>
>>> class vtkMyCallback : public vtkCommand
>>> {
>>> public:
>>>        vtkMyCallback::vtkMyCallback() { m_pvtkActorSelection = NULL; };
>>>        static vtkMyCallback *New() { return new vtkMyCallback; }
>>>        void SetSelectionActor(vtkActor* pvtkActorSelection) {
>>> m_pvtkActorSelection = pvtkActorSelection; };
>>>        void SetSelectionList(vtkIdList* pvtkIdDeletion) {
>>> m_pvtkIdDeletion = pvtkIdDeletion; };
>>>        void SetSelectionDataSet(vtkPolyData* pvtkDataSet) {
>>> m_pvtkDataSet = pvtkDataSet; };
>>>        void SetIren(vtkRenderWindowInteractor* pvtkIren) { m_pvtkIren =
>>> pvtkIren; };
>>>        void SetSelectionMapper(vtkPolyDataMapper* pvtkDataMapper) {
>>> m_pvtkDataMapper = pvtkDataMapper; };
>>>        virtual void Execute(vtkObject *caller, unsigned long, void*)
>>>        {
>>>                double coords[3];
>>>                int pId;
>>>                float ptr;
>>>                vtkCellPicker *picker = (vtkCellPicker
>>> *)m_pvtkIren->GetPicker();
>>>                picker->GetPickPosition(coords);
>>>                // Obter o Id da cell que acabamos de fazer pickin
>>>                pId = picker->GetCellId();
>>>              
>>> m_pvtkDataSet->GetPointData()->GetScalars()->SetTuple1(pId,0);
>>> ------------------------------------------------------------
>>>              
>>> m_pvtkDataSet->Update();------------------------------------------------------------------------------------------------------
>>>
>>>
>>>              
>>> m_pvtkDataMapper->SetInput(m_pvtkDataSet);--------------------------------------------------------------------------------
>>>
>>>
>>>                              printf("Cell ID a remover: %d \n",pId);
>>>                // Inserção da cell na vtkIdList
>>>                m_pvtkIdDeletion->InsertNextId(pId);
>>>                // Caso a cell já esteja na vtkIdList ou seja NULL(-1)
>>>                for(int k=0; k<m_pvtkIdDeletion->GetNumberOfIds(); k++)
>>>                {
>>>                    if ((pId) == (m_pvtkIdDeletion->GetId(k)) && (k!=0))
>>>                    {
>>>                        m_pvtkIdDeletion->DeleteId(pId);
>>>                        m_pvtkIdDeletion->InsertNextId(pId);
>>>                    }
>>>                    if ((pId) == -1)
>>>                        m_pvtkIdDeletion->DeleteId(pId);
>>>                }
>>>              
>>> printf("-------------------------------------------------------------------------\n");
>>>
>>>
>>>                printf("Numero de Cells para
>>> remocao:%d\n",m_pvtkIdDeletion->GetNumberOfIds());
>>>                printf("Lista de Cells para remocao:\n");
>>>                for(int k=0; k<m_pvtkIdDeletion->GetNumberOfIds(); k++)
>>>                    printf("Pos:%d
>>> CellId:%d\n",k,m_pvtkIdDeletion->GetId(k));
>>>                // Renderizar a nossa esfera de picking para a cell
>>> seleccionada
>>>                if (picker->GetCellId() != -1)
>>>                {
>>>                      if (m_pvtkActorSelection)        
>>>                          m_pvtkActorSelection->SetPosition(coords);
>>>                }
>>>                m_pvtkIren->Render();
>>>              
>>> //m_pvtkDataSet->GetPointData()->GetScalars()->SetTuple1(pId,1);
>>>        }
>>> private:
>>>        vtkActor* m_pvtkActorSelection;
>>>        vtkIdList* m_pvtkIdDeletion;
>>>        vtkPolyData* m_pvtkDataSet;
>>>        vtkRenderWindowInteractor* m_pvtkIren;
>>>        vtkPolyDataMapper* m_pvtkDataMapper;
>>> };
>>>
>>>
>>>
>>> Dominik Szczerba escreveu:
>>>    
>>>> you may need to set/update the range in the mapper
>>>> --ds
>>>>
>>>> Ricardo Seco VTK wrote:
>>>>  
>>>>      
>>>>> well i did after setting the tuple the update of my polydata object
>>>>> and
>>>>> nothing....
>>>>> any more sugestions?
>>>>>
>>>>> Ricardo Seco
>>>>>
>>>>> Dominik Szczerba escreveu:
>>>>>           
>>>>>> well you have to Update() something
>>>>>> --DS
>>>>>>
>>>>>> Ricardo Seco VTK wrote:
>>>>>>  
>>>>>>               
>>>>>>> Hello. I am trying to change the color of the cell after picking but
>>>>>>> nothing happens...
>>>>>>> Could someone help me?
>>>>>>>
>>>>>>> Best Regards
>>>>>>> Ricardo Seco
>>>>>>>
>>>>>>> class vtkMyCallback : public vtkCommand
>>>>>>> {
>>>>>>> public:
>>>>>>>        vtkMyCallback::vtkMyCallback() { m_pvtkActorSelection =
>>>>>>> NULL; };
>>>>>>>        static vtkMyCallback *New() { return new vtkMyCallback; }
>>>>>>>        void SetSelectionActor(vtkActor* pvtkActorSelection) {
>>>>>>> m_pvtkActorSelection = pvtkActorSelection; };
>>>>>>>        void SetSelectionList(vtkIdList* pvtkIdDeletion) {
>>>>>>> m_pvtkIdDeletion = pvtkIdDeletion; };
>>>>>>>        void SetSelectionDataSet(vtkPolyData* pvtkDataSet) {
>>>>>>> m_pvtkDataSet = pvtkDataSet; };
>>>>>>>        void SetIren(vtkRenderWindowInteractor* pvtkIren) {
>>>>>>> m_pvtkIren =
>>>>>>> pvtkIren; };
>>>>>>>        virtual void Execute(vtkObject *caller, unsigned long, void*)
>>>>>>>        {
>>>>>>>                double coords[3];
>>>>>>>                int pId;
>>>>>>>                float ptr;
>>>>>>>                vtkCellPicker *picker = (vtkCellPicker
>>>>>>> *)m_pvtkIren->GetPicker();
>>>>>>>                picker->GetPickPosition(coords);
>>>>>>>                // Obter o Id da cell que acabamos de fazer pickin
>>>>>>>                pId = picker->GetCellId();
>>>>>>>            
>>>>>>> m_pvtkDataSet->GetPointData()->GetScalars()->SetTuple1(pId,0);--------------------------------------------------
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> HERE
>>>>>>>                              printf("Cell ID a remover: %d \n",pId);
>>>>>>>                // Inserção da cell na vtkIdList
>>>>>>>                m_pvtkIdDeletion->InsertNextId(pId);
>>>>>>>                // Caso a cell já esteja na vtkIdList ou seja
>>>>>>> NULL(-1)
>>>>>>>                for(int k=0; k<m_pvtkIdDeletion->GetNumberOfIds();
>>>>>>> k++)
>>>>>>>                {
>>>>>>>                    if ((pId) == (m_pvtkIdDeletion->GetId(k)) &&
>>>>>>> (k!=0))
>>>>>>>                    {
>>>>>>>                        m_pvtkIdDeletion->DeleteId(pId);
>>>>>>>                        m_pvtkIdDeletion->InsertNextId(pId);
>>>>>>>                    }
>>>>>>>                    if ((pId) == -1)
>>>>>>>                        m_pvtkIdDeletion->DeleteId(pId);
>>>>>>>                }
>>>>>>>            
>>>>>>> printf("-------------------------------------------------------------------------\n");
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>                printf("Numero de Cells para
>>>>>>> remocao:%d\n",m_pvtkIdDeletion->GetNumberOfIds());
>>>>>>>                printf("Lista de Cells para remocao:\n");
>>>>>>>                for(int k=0; k<m_pvtkIdDeletion->GetNumberOfIds();
>>>>>>> k++)
>>>>>>>                    printf("Pos:%d
>>>>>>> CellId:%d\n",k,m_pvtkIdDeletion->GetId(k));
>>>>>>>                // Renderizar a nossa esfera de picking para a cell
>>>>>>> seleccionada
>>>>>>>                if (picker->GetCellId() != -1)
>>>>>>>                {
>>>>>>>                      if (m_pvtkActorSelection)      
>>>>>>>                          m_pvtkActorSelection->SetPosition(coords);
>>>>>>>                }
>>>>>>>                m_pvtkIren->Render();
>>>>>>>            
>>>>>>> m_pvtkDataSet->GetPointData()->GetScalars()->SetTuple1(pId,1);
>>>>>>>        }
>>>>>>> private:
>>>>>>>        vtkActor* m_pvtkActorSelection;
>>>>>>>        vtkIdList* m_pvtkIdDeletion;
>>>>>>>        vtkPolyData* m_pvtkDataSet;
>>>>>>>        vtkRenderWindowInteractor* m_pvtkIren;
>>>>>>> };
>>>>>>> _______________________________________________
>>>>>>> This is the private VTK discussion list. Please keep messages
>>>>>>> on-topic.
>>>>>>> Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>>>>>>> Follow this link to subscribe/unsubscribe:
>>>>>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>>>>>>                         
>>>>>>                   
>>>>> _______________________________________________
>>>>> This is the private VTK discussion list. Please keep messages
>>>>> on-topic.
>>>>> Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>>>>> Follow this link to subscribe/unsubscribe:
>>>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>>>>             
>>>>         
>>> _______________________________________________
>>> This is the private VTK discussion list. Please keep messages on-topic.
>>> Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>>     
>>
>>   
> 
> _______________________________________________
> This is the private VTK discussion list. Please keep messages on-topic.
> Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers



More information about the vtkusers mailing list