64
Faculdade de Engenharia da Universidade do Porto Faculdade de Ciências da Universidade do Porto MESTRADO EM MÉTODOS COMPUTACIONAIS EM CIÊNCIAS E ENGENHARIA 2004/ 2005 Disciplina de Visualização Científica Visualização da estrutura cristalina e magnética utilizando o VTK André Miguel Trindade Pereira 21 de Abril de 2005

Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Faculdade de Engenharia da Universidade do Porto Faculdade de Ciências da Universidade do Porto

MMEESSTTRRAADDOO EEMM MMÉÉTTOODDOOSS CCOOMMPPUUTTAACCIIOONNAAIISS EEMM CCIIÊÊNNCCIIAASS EE EENNGGEENNHHAARRIIAA 22000044// 22000055

Disciplina de

Visualização Científica

Visualização da estrutura cristalina e magnética

utilizando o VTK

André Miguel Trindade Pereira 21 de Abril de 2005

Page 2: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

INDICE INTRODUÇÃO 1

OBJECTIVOS DO TRABALHO 3

METEDOLOGIA USADA 4

Definição de classes: 4

Abertura/ Leitura de Ficheiros 5

Construção de menus 5

Construção de Actores 6

Luz 10

Câmara 10

Animação 11

Render (cena) 12

Janelas 13

Interacção 13

RESULTADOS OBTIDOS 14

Visualização da Estrutura Cristalográfica 15

Visualização da Estrutura Magnética 15

Simulação da transição estrutural 16

Simulação da reorientação de spin 17

CONCLUSÕES 18

BIBLIOGRAFIA 19

ANEXO I (Lib’s) 20

ANEXO II (programa) 21

Page 3: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 1 -

INTRODUÇÃO

A Visualização Computacional é uma nova área da computação que se encontra em

amplo desenvolvimento actualmente. Permite manipular, com o auxílio de software

adequado, diferentes tipos de dados, transformando-os em imagens gráficas, de modo a

facilitar a sua interpretação.

Com a evolução das Tecnologias de Informação e Comunicação, a quantidade de

informações disponibilizadas tem aumentado consideravelmente, tornando-se

imperativo encontrar formas de representar essas informações, para uma mais fácil e

rápida compreensão.

O VTK, The Visualization Toolkit, é um dos softwares usados neste processo. O

VTK é um sistema de software de código-fonte aberto, para computação gráfica

tridimensional (3D), processamento de imagem e visualização. Consiste numa

biblioteca de classes C++ associada a diversas interfaces interpretadas, nomeadamente

Tcl/ Tk, Java e Python. Este software suporta uma vasta gama de algoritmos de

visualização (como por exemplo métodos escalares, vectoriais, de textura, tensoriais e

volumétricos), assim como técnicas de modelamento avançado (como por exemplo,

modelamento implícito, redução poligonal, triangulação de Delaunay, suavização de

malhas, definição de contornos e corte) e dezenas de algoritmos de processamento de

imagem.

É uma ferramenta computacional utilizada em diversos ramos da Ciência e

Engenharia nomeadamente em Medicina, Física, Química, Meteorologia, Mecânica,

Programação, Investigação Científica, Matemática, Modelação Molecular, cursos

superiores de Computação Gráfica e de Visualização, entre outros.

As simulações computacionais de redes atómicas e moleculares a 3D são uma

ferramenta essencial em áreas como a Física, Química e Biologia, para a compreensão

Page 4: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 2 -

das propriedades macroscópicas dos materiais, auxiliando na interpretação dos

fenómenos observados. O software VTK para além de permitir simular as moléculas a

3D, também permite mover os objectos visualizados, fornecendo novas informações

sobre a sua estrutura espacial, segundo diferentes perspectivas.

Este trabalho tem como principal objectivo construir um programa que permita

visualizar redes cristalinas, em particular a estrutura cristalográfica do composto

intermetálico Tb5Si2Ge2, também analisado na tese final de Mestrado. Para realizar esta

simulação tridimensional recorreu-se à biblioteca gráfica do VTK.

O composto Tb5Si2Ge2 (composto contendo átomos de térbio, silício e germânio) é

utilizado em diversas aplicações nomeadamente em refrigeração magnética e em

microssensores. Este composto apresenta uma célula unitária ortorrômbica do tipo

Pnma (paralelepípedo), contendo 36 átomos no seu interior (Figura 1). Desses, 20 são

átomos de Térbio e 16 são átomos de Silício ou de Germânio.

Figura 1 - Célula unitária do composto Tb5Si2Ge2

Cada um dos átomos é representado por uma esfera, utilizando-se diferentes cores

para distinguir as diferentes posições dos átomos.

Page 5: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 3 -

OBJECTIVOS DO TRABALHO

A primeira parte deste trabalho consiste em representar graficamente a célula

unitária, a três dimensões, idêntica à que é apresentada na Figura 1, e conseguir

visualizá-la em qualquer perspectiva. Para construir esta representação utilizaram-se

dados obtidos por raios X, que são apresentados num ficheiro ASCII contendo o nome,

cor e raio dos átomos.

Numa segunda parte do trabalho pretende-se representar os momentos magnéticos

(spins magnéticos) dos átomos de térbio (Tb), colocando setas sobre os átomos, com a

respectiva direcção, para se poder estudar a influência da troca directa e do campo de

cristal (tema da tese de Mestrado). Estes dados são dados obtidos de difracção de

neutrões e estão apresentados num ficheiro ASCII.

Numa terceira fase, pretende-se simular a transição magneto-estrutural do composto,

isto é, simular o movimento dos átomos durante essa transição.

Numa última parte pretende-se simular a reorientação de spin, fazendo rodar as setas

dos momentos magnéticos.

Em síntese, pretende-se:

Representar graficamente a célula unitária a 3D;

Representar graficamente a estrutura magnética do composto;

Simular a transição magneto-estrutural do composto;

Simular a reorientação de spin do composto.

Page 6: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 4 -

METODOLOGIA USADA

Neste capítulo serão descritos os aspectos principais do programa elaborado neste

trabalho. Para tal irão sendo apresentados extractos do código do programa principal,

explicando sucintamente a sua função.

1. Definição de classes:

O primeiro passo consiste em definir as classes a utilizar. No programa principal

utilizaram-se várias classes como se pode ver nas linhas de código seguintes:

#include "vtkOutlineFilter.h" #include "vtkVectorText.h" #include "vtkPoints.h" #include "vtkPointData.h" #include "vtkSphereSource.h" #include "vtkArrowSource.h" #include "vtkCellArray.h" #include "vtkFloatArray.h" #include "vtkPolyData.h" #include "vtkPolyDataMapper.h" #include "vtkRectilinearGridGeometryFilter.h" #include "vtkActor.h" #include "vtkRectilinearGrid.h" #include "vtkRenderer.h" #include "vtkRenderWindow.h" #include "vtkRenderWindowInteractor.h" #include "vtkProperty.h" #include "vtkCamera.h" #include "vtkLight.h" #include "vtkAxes.h" #include "vtkTextMapper.h" #include "vtkTextProperty.h" #include "vtkActor2D.h" #include "vtkCommand.h" #include "vtkTextMapper.h" #include "vtkTextProperty.h" #include "vtkActor2D.h" #include <strstrea.h> #include <fstream.h> #include <iostream.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "stdafx.h"

Page 7: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 5 -

#include "mmsystem.h"

2. Abertura/ Leitura de Ficheiros

Neste programa a abertura de ficheiros é de extrema importância, tendo-se utilizado

o seguinte código:

FILE *input; // abertura do ficheiro principal dados.dat // Open for read (will fail if file does not exist) if( (input = fopen("dados.dat", "r")) == NULL) { printf("\nO ficheiro 'dados.dat' não foi aberto\n"); return 1; } else printf("\nO ficheiro 'dados.dat' foi aberto \n");

Como se pode verificar, foi criada uma linha de código que permite avisar o

utilizador, no caso do ficheiro não ser aberto.

O código seguinte permite imprimir para a consola de MS-DOS os resultados

obtidos da leitura do ficheiro:

while (fscanf(input, "%lf %lf\n", &phiT[n+1], &thetaT[n+1]) != EOF) { n++; printf("\n Point %d angulo Tsr phi=%lf, theta=%lf",n, phiT[n], thetaT[n]); }

3. Construção de menus

Para construir os menus basta mandar imprimir as opções: printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); printf("\n\n ///////////////////////////////////////////////////////////////////////////////\n\n"); printf(" -----------------------------------MENU---------------------------------\n\n");

Page 8: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 6 -

printf("\t ATENCAO: Este programa diferencia maisculas de minusculas \n\n\n"); printf ("\t \t C-Visualizacao da Estrutura Cristalografica \n\n\n"); printf (" \t \t M-Visualizacao da Estrutura Magnetica \n\n\n"); printf ("\t \t S-Simulacao da transicao estrutural \n\n\n"); printf ("\t \t H-Simulacao da reorientacao de spin \n\n\n"); printf("////////////////////////////////////////////////////////////////////////////////\n\n"); printf("\n\n\n\n");

Para seleccionar a opção pretendida, utilizou-se o seguinte código (primeiro

identifica a opção e depois manda-a executar):

util = getchar(); if ( util == 'C') { ... ... } if ( util != 'H' && util != 'S' && util != 'M' && util != 'C') { printf ("\n\n Voce nao escolheu nenhuma das opcoes dadas\n"); printf ("\n\n O programa desliga-se automaticamente volte a tentar por favor\n"); printf ("\n\n para isso carregue em qualquer tecla \n"); }

No caso de não ser seleccionada qualquer opção, foi criado um controlo que avisa

que não foi seleccionada nenhuma das opções indicadas.

4. Actores Nesta subsecção, de uma forma sintetizada, vai ser descrito como são formados os actores utilizados no programa:

• Criação de esferas que representam os átomos Para se criar uma esfera utiliza-se uma classe própria do VTK que tem o nome de

vtkSphereSource.h. Nesta classe podemos definir a resolução da esfera (número de

pontos ao longo de φ e θ, em coordenadas esféricas). vtkSphereSource *sphere = vtkSphereSource::New(); sphere->SetThetaResolution(100); sphere->SetPhiResolution(50);

Page 9: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 7 -

Para se fazer o mapper da esfera utiliza-se a classe vtkPolyDataMapper.h, que

utiliza a fonte (source) anterior:

vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New(); sphereMapper->SetInput(sphere->GetOutput());

De seguida basta criar o actor para obter a esfera. Para criar vários actores esféricos

basta uma única Source e um único Mapper.

Para uma única esfera tem-se o seguinte código:

sphere1 = vtkActor::New(); sphere1->SetMapper(sphereMapper); sphere1->GetProperty()->SetColor(0,0,1); sphere1->GetProperty()->SetAmbient(0.3); sphere1->GetProperty()->SetDiffuse(0.5); sphere1->GetProperty()->SetSpecular(1.0); sphere1->GetProperty()->SetSpecularPower(20.0); sphere1->AddPosition(x[1],y[1],z[1]);

Na criação do actor podem-se modificar várias propriedades como a cor (no sistema

RGB), a tonalidade e a intensidade. No final indica-se a posição onde será criado o actor

(posição que foi lida no ficheiro: dados.dat).

• Criação de setas Para criar as setas utilizou-se uma classe específica do VTK que é o

vtkArrowSource.h. Esta classe cria uma seta unindo a base de um cone a uma das bases

de um cilindro.

vtkArrowSource *arrow = vtkArrowSource::New();

O procedimento seguinte é idêntico ao utilizado no caso da esfera, isto é, faz-se o

mapeamento e depois cria-se o actor, que pode ter várias propriedades.

vtkPolyDataMapper *arrowMapper = vtkPolyDataMapper::New(); arrowMapper->SetInput(arrow->GetOutput());

Page 10: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 8 -

vtkActor *arrowactor1 = vtkActor::New(); arrowactor1->SetMapper(arrowMapper); arrowactor1->SetPosition(x[1]-0.5, y[1], z[1]); arrowactor1->SetScale(2); (arrowactor1->GetProperty())->SetColor(0.5, 0.5, 0.5); arrowactor1->RotateZ(phi[1]); arrowactor1->RotateX(theta[1]);

Analisando o código anterior pode-se observar que é possível modificar algumas

propriedades da seta tais como a cor, a posição, o factor de escala e o sentido (rotação

em coordenadas esféricas).

• Criação do cabeçalho

Para criar o cabeçalho utiliza-se uma classe própria do vtkTextMapper.h que cria

um texto, podendo-se modificar vários tipos de formatações (tamanho da fonte, tipo de

fonte, cor, etc.).

De seguida utiliza-se outra classe que é o vtkActor2D.h para criar um actor 2D,

podendo-se definir várias propriedades (como, por exemplo, a posição):

char *text = "T = 2 K"; vtkTextMapper *pText = vtkTextMapper::New(); pText->SetInput(text); vtkTextProperty *propText = pText->GetTextProperty(); propText->SetFontSize(18); propText->SetFontFamilyToArial(); propText->SetColor(0,0,1); propText->BoldOn(); propText->ItalicOff(); propText->ShadowOff(); propText->SetJustificationToLeft(); propText->SetVerticalJustificationToBottom(); vtkActor2D *pActor = vtkActor2D::New(); pActor->SetMapper(pText); pActor->SetPosition(150,250);

• Criação dos parâmetros da rede

O código seguinte serve para criar os parâmetros da célula unitária, sendo a, b, c os

parâmetros da rede. Nesta parte do trabalho utilizaram-se as seguintes classes do VTK:

a. vtkPoints.h – Classe do VTK que recolhe os pontos e recnhece-os.

Page 11: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 9 -

b. vtkCellArray – Classe do VTK que vai gerar uma célula fazendo

ligação entre os pontos.

Posteriormente fez-se o mapper e por fim criou-se o actor, utilizando-se, para a

representação, o wireframe (isto é, o esqueleto da célula).

a=7.4313; b=14.6278; c=7.7151; static float q[8][3]={{0,0,0}, {a,0,0}, {a,b,0}, {0,b,0}, {0,0,c}, {a,0,c}, {a,b,c}, {0,b,c}}; static vtkIdType pts[6][4]={{0,1,2,3}, {4,5,6,7}, {0,1,5,4}, {1,2,6,5}, {2,3,7,6}, {3,0,4,7}}; vtkPolyData *celula = vtkPolyData::New(); vtkPoints *points = vtkPoints::New(); vtkCellArray *polys=vtkCellArray::New(); int j; for (j=0; j<8; j++) points->InsertPoint(j,q[j]); for (j=0; j<6; j++) polys->InsertNextCell(4,pts[j]); celula->SetPoints(points); points->Delete(); celula->SetPolys(polys); polys->Delete(); vtkPolyDataMapper *celulaMapper = vtkPolyDataMapper::New(); celulaMapper->SetInput(celula); vtkActor *celulaActor = vtkActor::New(); celulaActor->SetMapper(celulaMapper); celulaActor->GetProperty()->SetRepresentationToWireframe();

• Criação dos eixos

Para criar os eixos utilizou-se uma classe do VTK denominada de vtkAxes.h. Esta

função cria a Source dos eixos, podendo-se escolher a posição da origem, o factor de

escala e a simetria. Depois mapeamos a Source e criamos o actor.

vtkAxes *axes=vtkAxes::New();

axes->SetOrigin(0,0,0); axes->SetScaleFactor(1);

Page 12: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 10 -

axes->SymmetricOn(); vtkPolyDataMapper *axesMapper=vtkPolyDataMapper::New(); axesMapper->SetInput(axes->GetOutput()); vtkActor *axesActor=vtkActor::New(); axesActor->SetMapper(axesMapper); axesMapper->Delete();

• Criação dos labels dos eixos

Para etiquetar as direcções dos eixos utilizou-se a classe vtkVectorText.h. O

processo é semelhante a todos os outros, isto é, mapeamos e depois criamos o actor.

vtkVectorText *texta=vtkVectorText::New(); texta->SetText("a"); vtkPolyDataMapper *textaMapper=vtkPolyDataMapper::New(); textaMapper->SetInput(texta->GetOutput()); vtkActor *textaActor=vtkActor::New(); textaActor->SetMapper(textaMapper); textaActor->SetPosition(1,0,-0.5); textaActor->SetScale(0.5); textaActor->GetProperty()->SetColor(1,0,0); ren1->AddActor(textaActor);

5. Luz

É possível criar luz de modo a produzir sombras e efeitos de cor. Para tal, utilizou-se

a classe vtkLight.h.

vtkLight *light = vtkLight::New(); light->SetFocalPoint(1.875,0.6125,0); light->SetPosition(0.875,1.6125,1); ren1->AddLight(light);

6. Câmara

Para criar uma câmara utilizou-se a classe vtkCamera.h, que permite definir várias

propriedades tais como o ponto focal, a posição, etc.

Page 13: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 11 -

ren1->GetActiveCamera()->SetFocalPoint(0,0,0); ren1->GetActiveCamera()->SetPosition(0,10,0); ren1->ResetCamera(); ren1->GetActiveCamera()->SetParallelScale(5);

7. Animação

Para criar a animação utilizam-se funções específicas, neste caso, o

vtkMyCallback.h.

vtkMyCallback *mo1 = vtkMyCallback::New(); iren->CreateTimer(VTKI_TIMER_FIRST); iren->AddObserver(vtkCommand::TimerEvent, mo1, 2.0); timeLastCall = timeGetTime(); class vtkMyCallback : public vtkCommand { public: static vtkMyCallback *New() { return new vtkMyCallback; } void PrintSelf(ostream& os, vtkIndent indent) {} void PrintTrailer(ostream& os, vtkIndent indent) {} void PrintHeader(ostream& os, vtkIndent indent) {} void CollectRevisions(ostream& os) {} virtual void Execute(vtkObject *caller, unsigned long, void*) { vtkRenderWindowInteractor *ri = reinterpret_cast<vtkRenderWindowInteractor*>(caller); // a periodicidade da chamada depende do sistema operativo // e' necessario ver o tempo actual e verificar se ja decorreu o tempo // pretendido para fazer algo. //cout << "timer"; if ((timeGetTime() - timeLastCall) > 1000) { cout << "1 segundo" << endl; timeLastCall = timeGetTime(); sphere1->AddPosition(0.1,0, 0); sphere2->AddPosition(0.1,0, 0); sphere3->AddPosition(0.1,0, 0); sphere4->AddPosition(0.1,0, 0); sphere5->AddPosition(0.1,0, 0); sphere6->AddPosition(0.1,0, 0); sphere7->AddPosition(0.1,0, 0); sphere8->AddPosition(0.1,0, 0); sphere9->AddPosition(0.1,0, 0);

Page 14: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 12 -

sphere10->AddPosition(0.1,0, 0); sphere21->AddPosition(0.1,0, 0); sphere22->AddPosition(0.1,0, 0); sphere23->AddPosition(0.1,0, 0); sphere24->AddPosition(0.1,0, 0); sphere25->AddPosition(0.1,0, 0); sphere26->AddPosition(0.1,0, 0); sphere27->AddPosition(0.1,0, 0); sphere28->AddPosition(0.1,0, 0); sphere11->AddPosition(-0.1,0, 0); sphere12->AddPosition(-0.1,0, 0); sphere13->AddPosition(-0.1,0, 0); sphere14->AddPosition(-0.1,0, 0); sphere15->AddPosition(-0.1,0, 0); sphere16->AddPosition(-0.1,0, 0); sphere17->AddPosition(-0.1,0, 0); sphere18->AddPosition(-0.1,0, 0); sphere19->AddPosition(-0.1,0, 0); sphere20->AddPosition(-0.1,0, 0); sphere29->AddPosition(-0.1,0, 0); sphere30->AddPosition(-0.1,0, 0); sphere31->AddPosition(-0.1,0, 0); sphere32->AddPosition(-0.1,0, 0); sphere33->AddPosition(-0.1,0, 0); sphere34->AddPosition(-0.1,0, 0); sphere35->AddPosition(-0.1,0, 0); sphere36->AddPosition(-0.1,0, 0); } ri->GetRenderWindow()->Render(); AbortFlagOn(); // nao passa o evento para o vtkRenderWindowInteractor } }; Render

8. Render (cena)

Num filme, para além dos actores tem que se criar a cena. Em programação cria-se o

render onde se irão colocar os actores, através da classe vtkRenderer.h, programando-se

da seguinte forma:

vtkRenderer *ren1 = vtkRenderer::New(); vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->AddRenderer(ren1);

Para adicionar os actores ao render temos:

Page 15: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 13 -

Ren1->AddActor2D(pActor);

9. Janelas

Depois de criar a cena temos de utilizar as janelas para ver os actores e a cena. Para

se criar a janela utilizou-se a classe vtkRenderWindow.h.

vtkRenderWindow *renWin = vtkRenderWindow::New();

Para adicionar as cenas à janela temos de utilizar o seguinte código: renWin->AddRenderer(ren1);

10. Interacção

Para fazer as interacções do utilizador com os objectos (muito úteis para ver as

posições cristalográficas) usou-se a classe vtkRenderWindowInteractor.h.

vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); iren->SetRenderWindow(renWin);

Page 16: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 14 -

RESULTADOS OBTIDOS

Ao longo do capítulo anterior descreveu-se, de um modo sucinto, o código geral.

Neste capítulo serão descritas as funcionalidades do programa criado.

O programa inicia com a apresentação de um menu geral onde o utilizador pode

seleccionar a opções pretendida, como se pode verificar na Figura 2:

Figura 2 - Figura representativa da consola com o menu MS-DOS

Antes de iniciar a apresentação, o programa abre o ficheiro dados.dat, lê os pontos e

guarda-os num array.

Page 17: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 15 -

1. Visualização da Estrutura Cristalográfica (opção C)

Este programa vai formar a imagem da estrutura cristalográfica da célula unitária

com os 36 átomos no seu interior. As posições dos átomos são colocadas de acordo

com os valores do ficheiro dados.dat, obtidos experimentalmente por raios X.

Existe também uma interacção entre o utilizador e os objectos criados. Podemos

fazer zoom e rodar o sistema de modo a visualizar em pormenor a estrutura

cristalina.

O resultado final é apresentado na Figura 3.

Figura 3 Figura obtida seleccionanco a opção “C - Visualização da Estrutura Cristalográfica”

2. Visualização da Estrutura Magnética (opção M)

Nesta parte do programa representa-se unicamente a parte magnética (átomos de

Também, de cor azul) para posteriores análises das interacções magnéticas e

magneto-cristalinas. As setas representam os momentos magnéticos do átomos

(spin) que servirão para posteriores análises de anisotropia cristalina.

A direcção e sentido das setas são lidas num ficheiro (angulos.dat) que tem as

componentes em coordenadas esféricas.

O resultado final obtido é apresentado na Figura 4.

Page 18: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 16 -

Figura 4 - Figura obtida seleccionando a opção “M -Visualização da Estrutura Magnética”

Novamente existe interacção entre o utilizador e os objectos, permitindo obter

uma melhor visão da estrutura.

3. Simulação da transição estrutural (opção S)

Nesta parte do programa é simulada a transição estrutural. Esta transição estrutural

é originada pelo movimento dos átomos em dois sentidos opostos (metade para cada

lado). Nesta parte do trabalho retirou-se a célula unitária, para melhor observar a

visualização. O movimento dos átomos é efectuado com movimento de 0.1 em cada

segundo.

O resultado obtido é apresentado na Figura 5.

Figura 5 – Figura obtida seleccionando a opção “S - Simulação da Transição Estrutural”

Page 19: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 17 -

4. Simulação da reorientação de spin (opção H)

Para efectuar a simulação da reorientação de spin, poder-se-ía criar um programa

muito semelhante ao anterior. Contudo, tentei demonstrar outras potencialidades do

VTK.

Por outro lado, quando se pretende analisar com mais pormenor, normalmente

analisamos por planos. Em particular, no estudo da anisotropia cristalina (especialmente

deste composto) temos a necessidade de observar as duas figuras (em dois estados

diferentes) para compararmos as diferenças entre ambas. Como tal, optei por fazer duas

janelas de modo a apresentar os dois estados diferentes dos spins. Utilizei uma câmara

que vê de topo (na posição (0,10,0)). Assim, podemos mover os dois sistemas para

poder identificar e analisar as diferenças dos momentos magnéticos da estrutura

cristalográfica.

O resultado final é apresentado na Figura 6.

Figura 6 – Figura obtida seleccionando a opção “H - Simulação da reorientação de spin”.

Page 20: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 18 -

CONCLUSÕES

Após a concretização do programa de Visualização, conclui-se que foram atingidos

os objectivos inicialmente propostos para o trabalho integrado na disciplina de

Visualização Científica.

Ao longo do trabalho várias alterações foram efectuadas, tendo em vista o seu

aperfeiçoamento, e várias ideias novas foram sendo criadas. Por exemplo, a simulação

da reorientação de spin foi modificada, para não repetir o mesmo tipo de programação,

tentando explorar outras potencialidades do VTK.

Tal como foi referido na proposta inicial para a elaboração deste trabalho, este

possui uma importância extrema para o estudo efectuado na tese de Mestrado, mais

precisamente para o estudo da estrutura cristalina, anisotropia do sistema e apresentação

visual do mecanismo de transição estrutural e de reorientação de spin.

Algumas potencialidades do VTK foram exploradas no decurso deste trabalho, tendo

constatado a enorme importância deste software para visualização e manipulação virtual

de redes cristalinas.

Contudo, existe ainda um “mar de virtudes” intrínsecas ao VTK, a explorar...

Page 21: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 19 -

BIBLIOGRAFIA

• TAVARES, Dr. João, BARBOSA, Dr. Jorge, Notas da disciplina de

Visualização Científica 2004-2005, Faculdade de Engenharia da Universidade

do Porto (2005)

• VTK 4.2.1 Documentation

• Trabalhos da disciplina de Visualização Científica de 2003-2004

Page 22: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 20 -

ANEXO I

Lib utilizadas:

vtkRendering.lib

vtkFiltering.lib

vtkGraphics.lib

vtkIO.lib

vtkCommon.lib

vtkHybrid.lib

vtkImaging.lib

vtkParallel.lib

winmm.lib

Page 23: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 21 -

ANEXO II Programa final: /*========================================================================= Programa: Cristalografia Module: cristalografia.cxx Language: C++ Date: 2005/03/18 Version: 1.0 Autor: André Pereira =========================================================================*/ #include "vtkOutlineFilter.h" #include "vtkVectorText.h" #include "vtkPoints.h" #include "vtkPointData.h" #include "vtkSphereSource.h" #include "vtkArrowSource.h" #include "vtkCellArray.h" #include "vtkFloatArray.h" #include "vtkPolyData.h" #include "vtkPolyDataMapper.h" #include "vtkRectilinearGridGeometryFilter.h" #include "vtkActor.h" #include "vtkRectilinearGrid.h" #include "vtkRenderer.h" #include "vtkRenderWindow.h" #include "vtkRenderWindowInteractor.h" #include "vtkProperty.h" #include "vtkCamera.h" #include "vtkLight.h" #include "vtkAxes.h" #include "vtkTextMapper.h" #include "vtkTextProperty.h" #include "vtkActor2D.h" #include "vtkCommand.h" #include "vtkTextMapper.h" #include "vtkTextProperty.h" #include "vtkActor2D.h" #include <strstrea.h> #include <fstream.h> #include <iostream.h>

Page 24: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 22 -

#include <stdio.h> #include <stdlib.h> #include <string.h> #include "stdafx.h" #include "mmsystem.h" // contem a definicao de timeGetTime // apontadores declarados globais por serem usados no callback vtkRenderer *ren1; long timeLastCall=0; vtkActor *sphere1; vtkActor *sphere2; vtkActor *sphere3; vtkActor *sphere4; vtkActor *sphere5; vtkActor *sphere6; vtkActor *sphere7; vtkActor *sphere8; vtkActor *sphere9; vtkActor *sphere10; vtkActor *sphere11; vtkActor *sphere12; vtkActor *sphere13; vtkActor *sphere14; vtkActor *sphere15; vtkActor *sphere16; vtkActor *sphere17; vtkActor *sphere18; vtkActor *sphere19; vtkActor *sphere20; vtkActor *sphere21; vtkActor *sphere22; vtkActor *sphere23; vtkActor *sphere24; vtkActor *sphere25; vtkActor *sphere26; vtkActor *sphere27; vtkActor *sphere28; vtkActor *sphere29; vtkActor *sphere30; vtkActor *sphere31; vtkActor *sphere32; vtkActor *sphere33; vtkActor *sphere34; vtkActor *sphere35; vtkActor *sphere36; bool toogle=0; // Class Callback para ser utilizado coma interacção class vtkMyCallback : public vtkCommand { public: static vtkMyCallback *New() { return new vtkMyCallback; } void PrintSelf(ostream& os, vtkIndent indent) {} void PrintTrailer(ostream& os, vtkIndent indent) {} void PrintHeader(ostream& os, vtkIndent indent) {} void CollectRevisions(ostream& os) {}

Page 25: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 23 -

virtual void Execute(vtkObject *caller, unsigned long, void*) { vtkRenderWindowInteractor *ri = reinterpret_cast<vtkRenderWindowInteractor*>(caller); // a periodicidade da chamada depende do sistema operativo // e' necessario ver o tempo actual e verificar se ja decorreu o tempo // pretendido para fazer algo. //cout << "timer"; if ((timeGetTime() - timeLastCall) > 1000) { cout << "1 segundo" << endl; timeLastCall = timeGetTime(); sphere1->AddPosition(0.1,0, 0); sphere2->AddPosition(0.1,0, 0); sphere3->AddPosition(0.1,0, 0); sphere4->AddPosition(0.1,0, 0); sphere5->AddPosition(0.1,0, 0); sphere6->AddPosition(0.1,0, 0); sphere7->AddPosition(0.1,0, 0); sphere8->AddPosition(0.1,0, 0); sphere9->AddPosition(0.1,0, 0); sphere10->AddPosition(0.1,0, 0); sphere21->AddPosition(0.1,0, 0); sphere22->AddPosition(0.1,0, 0); sphere23->AddPosition(0.1,0, 0); sphere24->AddPosition(0.1,0, 0); sphere25->AddPosition(0.1,0, 0); sphere26->AddPosition(0.1,0, 0); sphere27->AddPosition(0.1,0, 0); sphere28->AddPosition(0.1,0, 0); sphere11->AddPosition(-0.1,0, 0); sphere12->AddPosition(-0.1,0, 0); sphere13->AddPosition(-0.1,0, 0); sphere14->AddPosition(-0.1,0, 0); sphere15->AddPosition(-0.1,0, 0); sphere16->AddPosition(-0.1,0, 0); sphere17->AddPosition(-0.1,0, 0); sphere18->AddPosition(-0.1,0, 0); sphere19->AddPosition(-0.1,0, 0); sphere20->AddPosition(-0.1,0, 0); sphere29->AddPosition(-0.1,0, 0); sphere30->AddPosition(-0.1,0, 0); sphere31->AddPosition(-0.1,0, 0); sphere32->AddPosition(-0.1,0, 0); sphere33->AddPosition(-0.1,0, 0); sphere34->AddPosition(-0.1,0, 0); sphere35->AddPosition(-0.1,0, 0); sphere36->AddPosition(-0.1,0, 0); } ri->GetRenderWindow()->Render();

Page 26: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 24 -

AbortFlagOn(); // nao passa o evento para o vtkRenderWindowInteractor } }; // Programa principal int main(int argc, char *argv[]) { FILE *input; // abertura do ficheiro principal dados.dat // Open for read (will fail if file does not exist) if( (input = fopen("dados.dat", "r")) == NULL) { printf("\nO ficheiro 'dados.dat' não foi aberto\n"); return 1; } else printf("\nO ficheiro 'dados.dat' foi aberto \n"); // le os dados // definição dos arrays de entrada (posições) int n; double x[37]; double y[37]; double z[37]; double r; char nome[10]; char util; n = 0; // Leitura e impressão dospontos do ficheiro while (fscanf(input, "%s %lf %lf %lf %lf\n",&nome, &x[n+1], &y[n+1], &z[n+1], &r) != EOF) { n++; printf("\n Point %d coords nome=%s, x=%lf, y=%lf, z=%lf r=%lf", n, nome, x[n], y[n], z[n], r); } // Impressão de um quadro de Menu onde poderá escolher-se o que queremos fazer printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");

Page 27: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 25 -

printf("\n\n ///////////////////////////////////////////////////////////////////////////////\n\n"); printf(" -----------------------------------MENU---------------------------------\n\n"); printf("\t ATENCAO: Este programa diferencia maisculas de minusculas \n\n\n"); printf ("\t \t C-Visualizacao da Estrutura Cristalografica \n\n\n"); printf (" \t \t M-Visualizacao da Estrutura Magnetica \n\n\n"); printf ("\t \t S-Simulacao da transicao estrutural \n\n\n"); printf ("\t \t H-Simulacao da reorientacao de spin \n\n\n"); printf("////////////////////////////////////////////////////////////////////////////////\n\n"); printf("\n\n\n\n"); util = getchar(); //Condição da escolha da letra C programa para visualizar a Estrutura Cristalografica if ( util == 'C') { // Criação de uma esfera por uma classe pré definida (Source) vtkSphereSource *sphere = vtkSphereSource::New(); sphere->SetThetaResolution(100); sphere->SetPhiResolution(50); // Mapeamento de uma esfera que depois irá ser utilizada em vários actores vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New(); sphereMapper->SetInput(sphere->GetOutput()); // Criação dos actores Neste caso temos 36 atomos: vtkActor *sphere1 = vtkActor::New(); sphere1->SetMapper(sphereMapper); sphere1->GetProperty()->SetColor(0,0,1); sphere1->GetProperty()->SetAmbient(0.3); sphere1->GetProperty()->SetDiffuse(0.5); sphere1->GetProperty()->SetSpecular(1.0); sphere1->GetProperty()->SetSpecularPower(20.0); sphere1->AddPosition(x[1],y[1],z[1]); vtkActor *sphere2 = vtkActor::New(); sphere2->SetMapper(sphereMapper); sphere2->GetProperty()->SetColor(0,0,1); sphere2->GetProperty()->SetAmbient(0.3); sphere2->GetProperty()->SetDiffuse(0.5); sphere2->GetProperty()->SetSpecular(1.0); sphere2->GetProperty()->SetSpecularPower(20.0); sphere2->AddPosition(x[2],y[2],z[2]); vtkActor *sphere3 = vtkActor::New();

Page 28: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 26 -

sphere3->SetMapper(sphereMapper); sphere3->GetProperty()->SetColor(0,0,1); sphere3->GetProperty()->SetAmbient(0.3); sphere3->GetProperty()->SetDiffuse(0.5); sphere3->GetProperty()->SetSpecular(1.0); sphere3->GetProperty()->SetSpecularPower(20.0); sphere3->AddPosition(x[3],y[3],z[3]); vtkActor *sphere4 = vtkActor::New(); sphere4->SetMapper(sphereMapper); sphere4->GetProperty()->SetColor(0,0,1); sphere4->GetProperty()->SetAmbient(0.3); sphere4->GetProperty()->SetDiffuse(0.5); sphere4->GetProperty()->SetSpecular(1.0); sphere4->GetProperty()->SetSpecularPower(20.0); sphere4->AddPosition(x[4],y[4],z[4]); vtkActor *sphere5 = vtkActor::New(); sphere5->SetMapper(sphereMapper); sphere5->GetProperty()->SetColor(0,0,1); sphere5->GetProperty()->SetAmbient(0.3); sphere5->GetProperty()->SetDiffuse(0.5); sphere5->GetProperty()->SetSpecular(1.0); sphere5->GetProperty()->SetSpecularPower(20.0); sphere5->AddPosition(x[5],y[5],z[5]); vtkActor *sphere6 = vtkActor::New(); sphere6->SetMapper(sphereMapper); sphere6->GetProperty()->SetColor(0,0,1); sphere6->GetProperty()->SetAmbient(0.3); sphere6->GetProperty()->SetDiffuse(0.5); sphere6->GetProperty()->SetSpecular(0.5); sphere6->GetProperty()->SetSpecularPower(20.0); sphere6->AddPosition(x[6],y[6],z[6]); vtkActor *sphere7 = vtkActor::New(); sphere7->SetMapper(sphereMapper); sphere7->GetProperty()->SetColor(0,0,1); sphere7->GetProperty()->SetAmbient(0.3); sphere7->GetProperty()->SetDiffuse(0.5); sphere7->GetProperty()->SetSpecular(0.5); sphere7->GetProperty()->SetSpecularPower(20.0); sphere7->AddPosition(x[7],y[7],z[7]); vtkActor *sphere8 = vtkActor::New(); sphere8->SetMapper(sphereMapper); sphere8->GetProperty()->SetColor(0,0,1); sphere8->GetProperty()->SetAmbient(0.3); sphere8->GetProperty()->SetDiffuse(0.5); sphere8->GetProperty()->SetSpecular(0.5); sphere8->GetProperty()->SetSpecularPower(20.0); sphere8->AddPosition(x[8],y[8],z[8]); vtkActor *sphere9 = vtkActor::New(); sphere9->SetMapper(sphereMapper); sphere9->GetProperty()->SetColor(0,0,1); sphere9->GetProperty()->SetAmbient(0.3); sphere9->GetProperty()->SetDiffuse(0.5); sphere9->GetProperty()->SetSpecular(1.0); sphere9->GetProperty()->SetSpecularPower(20.0); sphere9->AddPosition(x[9],y[9],z[9]);

Page 29: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 27 -

vtkActor *sphere10 = vtkActor::New(); sphere10->SetMapper(sphereMapper); sphere10->GetProperty()->SetColor(0,0,1); sphere10->GetProperty()->SetAmbient(0.3); sphere10->GetProperty()->SetDiffuse(0.5); sphere10->GetProperty()->SetSpecular(1.0); sphere10->GetProperty()->SetSpecularPower(20.0); sphere10->AddPosition(x[10],y[10],z[10]); vtkActor *sphere11 = vtkActor::New(); sphere11->SetMapper(sphereMapper); sphere11->GetProperty()->SetColor(0,0,1); sphere11->GetProperty()->SetAmbient(0.3); sphere11->GetProperty()->SetDiffuse(0.5); sphere11->GetProperty()->SetSpecular(1.0); sphere11->GetProperty()->SetSpecularPower(20.0); sphere11->AddPosition(x[11],y[11],z[11]); vtkActor *sphere12 = vtkActor::New(); sphere12->SetMapper(sphereMapper); sphere12->GetProperty()->SetColor(0,0,1); sphere12->GetProperty()->SetAmbient(0.3); sphere12->GetProperty()->SetDiffuse(0.5); sphere12->GetProperty()->SetSpecular(1.0); sphere12->GetProperty()->SetSpecularPower(20.0); sphere12->AddPosition(x[12],y[12],z[12]); vtkActor *sphere13 = vtkActor::New(); sphere13->SetMapper(sphereMapper); sphere13->GetProperty()->SetColor(0,0,1); sphere13->GetProperty()->SetAmbient(0.3); sphere13->GetProperty()->SetDiffuse(0.5); sphere13->GetProperty()->SetSpecular(0.5); sphere13->GetProperty()->SetSpecularPower(5.0); sphere13->AddPosition(x[13],y[13],z[13]); vtkActor *sphere14 = vtkActor::New(); sphere14->SetMapper(sphereMapper); sphere14->GetProperty()->SetColor(0,0,1); sphere14->GetProperty()->SetAmbient(0.3); sphere14->GetProperty()->SetDiffuse(0.5); sphere14->GetProperty()->SetSpecular(0.5); sphere14->GetProperty()->SetSpecularPower(20.0); sphere14->AddPosition(x[14],y[14],z[14]); vtkActor *sphere15 = vtkActor::New(); sphere15->SetMapper(sphereMapper); sphere15->GetProperty()->SetColor(0,0,1); sphere15->GetProperty()->SetAmbient(0.3); sphere15->GetProperty()->SetDiffuse(0.5); sphere15->GetProperty()->SetSpecular(0.5); sphere15->GetProperty()->SetSpecularPower(20.0); sphere15->AddPosition(x[15],y[15],z[15]); vtkActor *sphere16 = vtkActor::New(); sphere16->SetMapper(sphereMapper); sphere16->GetProperty()->SetColor(0,0,1); sphere16->GetProperty()->SetAmbient(0.3); sphere16->GetProperty()->SetDiffuse(0.5); sphere16->GetProperty()->SetSpecular(0.5);

Page 30: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 28 -

sphere16->GetProperty()->SetSpecularPower(20.0); sphere16->AddPosition(x[16],y[16],z[16]); vtkActor *sphere17 = vtkActor::New(); sphere17->SetMapper(sphereMapper); sphere17->GetProperty()->SetColor(0,0,1); sphere17->GetProperty()->SetAmbient(0.3); sphere17->GetProperty()->SetDiffuse(0.5); sphere17->GetProperty()->SetSpecular(1.0); sphere17->GetProperty()->SetSpecularPower(20.0); sphere17->AddPosition(x[17],y[17],z[17]); vtkActor *sphere18 = vtkActor::New(); sphere18->SetMapper(sphereMapper); sphere18->GetProperty()->SetColor(0,0,1); sphere18->GetProperty()->SetAmbient(0.3); sphere18->GetProperty()->SetDiffuse(0.5); sphere18->GetProperty()->SetSpecular(1.0); sphere18->GetProperty()->SetSpecularPower(20.0); sphere18->AddPosition(x[18],y[18],z[18]); vtkActor *sphere19 = vtkActor::New(); sphere19->SetMapper(sphereMapper); sphere19->GetProperty()->SetColor(0,0,1); sphere19->GetProperty()->SetAmbient(0.3); sphere19->GetProperty()->SetDiffuse(0.5); sphere19->GetProperty()->SetSpecular(1.0); sphere19->GetProperty()->SetSpecularPower(20.0); sphere19->AddPosition(x[19],y[19],z[19]); vtkActor *sphere20 = vtkActor::New(); sphere20->SetMapper(sphereMapper); sphere20->GetProperty()->SetColor(0,0,1); sphere20->GetProperty()->SetAmbient(0.3); sphere20->GetProperty()->SetDiffuse(0.5); sphere20->GetProperty()->SetSpecular(1.0); sphere20->GetProperty()->SetSpecularPower(20.0); sphere20->AddPosition(x[20],y[20],z[20]); vtkActor *sphere21 = vtkActor::New(); sphere21->SetMapper(sphereMapper); sphere21->GetProperty()->SetColor(1,0,0); sphere21->GetProperty()->SetAmbient(0.3); sphere21->GetProperty()->SetDiffuse(0.5); sphere21->GetProperty()->SetSpecular(1.0); sphere21->GetProperty()->SetSpecularPower(20.0); sphere21->AddPosition(x[21],y[21],z[21]); vtkActor *sphere22 = vtkActor::New(); sphere22->SetMapper(sphereMapper); sphere22->GetProperty()->SetColor(1,0,0); sphere22->GetProperty()->SetAmbient(0.3); sphere22->GetProperty()->SetDiffuse(0.5); sphere22->GetProperty()->SetSpecular(1.0); sphere22->GetProperty()->SetSpecularPower(20.0); sphere22->AddPosition(x[22],y[22],z[22]); vtkActor *sphere23 = vtkActor::New(); sphere23->SetMapper(sphereMapper); sphere23->GetProperty()->SetColor(0,1,0);

Page 31: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 29 -

sphere23->GetProperty()->SetAmbient(0.3); sphere23->GetProperty()->SetDiffuse(0.5); sphere23->GetProperty()->SetSpecular(1.0); sphere23->GetProperty()->SetSpecularPower(20.0); sphere23->AddPosition(x[23],y[23],z[23]); vtkActor *sphere24 = vtkActor::New(); sphere24->SetMapper(sphereMapper); sphere24->GetProperty()->SetColor(0,1,0); sphere24->GetProperty()->SetAmbient(0.3); sphere24->GetProperty()->SetDiffuse(0.5); sphere24->GetProperty()->SetSpecular(1.0); sphere24->GetProperty()->SetSpecularPower(20.0); sphere24->AddPosition(x[24],y[24],z[24]); vtkActor *sphere25 = vtkActor::New(); sphere25->SetMapper(sphereMapper); sphere25->GetProperty()->SetColor(0,1,0); sphere25->GetProperty()->SetAmbient(0.3); sphere25->GetProperty()->SetDiffuse(0.5); sphere25->GetProperty()->SetSpecular(0.5); sphere25->GetProperty()->SetSpecularPower(20.0); sphere25->AddPosition(x[25],y[25],z[25]); vtkActor *sphere26 = vtkActor::New(); sphere26->SetMapper(sphereMapper); sphere26->GetProperty()->SetColor(0,1,0); sphere26->GetProperty()->SetAmbient(0.3); sphere26->GetProperty()->SetDiffuse(0.3); sphere26->GetProperty()->SetSpecular(0.5); sphere26->GetProperty()->SetSpecularPower(20.0); sphere26->AddPosition(x[26],y[26],z[26]); vtkActor *sphere27 = vtkActor::New(); sphere27->SetMapper(sphereMapper); sphere27->GetProperty()->SetColor(1,0,0); sphere27->GetProperty()->SetAmbient(0.3); sphere27->GetProperty()->SetDiffuse(0.3); sphere27->GetProperty()->SetSpecular(0.5); sphere27->GetProperty()->SetSpecularPower(20.0); sphere27->AddPosition(x[27],y[27],z[27]); vtkActor *sphere28 = vtkActor::New(); sphere28->SetMapper(sphereMapper); sphere28->GetProperty()->SetColor(1,0,0); sphere28->GetProperty()->SetAmbient(0.3); sphere28->GetProperty()->SetDiffuse(0.3); sphere28->GetProperty()->SetSpecular(0.5); sphere28->GetProperty()->SetSpecularPower(20.0); sphere28->AddPosition(x[28],y[28],z[28]); vtkActor *sphere29 = vtkActor::New(); sphere29->SetMapper(sphereMapper); sphere29->GetProperty()->SetColor(1,0,0); sphere29->GetProperty()->SetAmbient(0.3); sphere29->GetProperty()->SetDiffuse(0.5); sphere29->GetProperty()->SetSpecular(1.0); sphere29->GetProperty()->SetSpecularPower(20.0); sphere29->AddPosition(x[29],y[29],z[29]); vtkActor *sphere30 = vtkActor::New();

Page 32: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 30 -

sphere30->SetMapper(sphereMapper); sphere30->GetProperty()->SetColor(1,0,0); sphere30->GetProperty()->SetAmbient(0.3); sphere30->GetProperty()->SetDiffuse(0.5); sphere30->GetProperty()->SetSpecular(1.0); sphere30->GetProperty()->SetSpecularPower(20.0); sphere30->AddPosition(x[30],y[30],z[30]); vtkActor *sphere31 = vtkActor::New(); sphere31->SetMapper(sphereMapper); sphere31->GetProperty()->SetColor(0,1,0); sphere31->GetProperty()->SetAmbient(0.3); sphere31->GetProperty()->SetDiffuse(0.5); sphere31->GetProperty()->SetSpecular(1.0); sphere31->GetProperty()->SetSpecularPower(20.0); sphere31->AddPosition(x[31],y[31],z[31]); vtkActor *sphere32 = vtkActor::New(); sphere32->SetMapper(sphereMapper); sphere32->GetProperty()->SetColor(0,1,0); sphere32->GetProperty()->SetAmbient(0.3); sphere32->GetProperty()->SetDiffuse(0.5); sphere32->GetProperty()->SetSpecular(1.0); sphere32->GetProperty()->SetSpecularPower(20.0); sphere32->AddPosition(x[32],y[32],z[32]); vtkActor *sphere33 = vtkActor::New(); sphere33->SetMapper(sphereMapper); sphere33->GetProperty()->SetColor(0,1,0); sphere33->GetProperty()->SetAmbient(0.3); sphere33->GetProperty()->SetDiffuse(0.5); sphere33->GetProperty()->SetSpecular(0.5); sphere33->GetProperty()->SetSpecularPower(20.0); sphere33->AddPosition(x[33],y[33],z[33]); vtkActor *sphere34 = vtkActor::New(); sphere34->SetMapper(sphereMapper); sphere34->GetProperty()->SetColor(0,1,0); sphere34->GetProperty()->SetAmbient(0.3); sphere34->GetProperty()->SetDiffuse(0.5); sphere34->GetProperty()->SetSpecular(0.5); sphere34->GetProperty()->SetSpecularPower(20.0); sphere34->AddPosition(x[34],y[34],z[34]); vtkActor *sphere35 = vtkActor::New(); sphere35->SetMapper(sphereMapper); sphere35->GetProperty()->SetColor(1,0,0); sphere35->GetProperty()->SetAmbient(0.3); sphere35->GetProperty()->SetDiffuse(0.5); sphere35->GetProperty()->SetSpecular(0.5); sphere35->GetProperty()->SetSpecularPower(20.0); sphere35->AddPosition(x[35],y[35],z[35]); vtkActor *sphere36 = vtkActor::New(); sphere36->SetMapper(sphereMapper); sphere36->GetProperty()->SetColor(1,0,0); sphere36->GetProperty()->SetAmbient(0.3); sphere36->GetProperty()->SetDiffuse(0.5); sphere36->GetProperty()->SetSpecular(0.5); sphere36->GetProperty()->SetSpecularPower(20.0); sphere36->AddPosition(x[36],y[36],z[36]);

Page 33: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 31 -

// Criação da acção + da janela vtkRenderer *ren1 = vtkRenderer::New(); vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->AddRenderer(ren1); vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); iren->SetRenderWindow(renWin); // Criação da Texto char *text = "Estrutura Cristalografica"; vtkTextMapper *pText = vtkTextMapper::New(); pText->SetInput(text); vtkTextProperty *propText = pText->GetTextProperty(); propText->SetFontSize(18); propText->SetFontFamilyToArial(); propText->SetColor(0,0,1); propText->BoldOn(); propText->ItalicOff(); propText->ShadowOff(); propText->SetJustificationToLeft(); propText->SetVerticalJustificationToBottom(); vtkActor2D *pActor = vtkActor2D::New(); pActor->SetMapper(pText); pActor->SetPosition(425,650); // Adicionar os actores ao render e escolha da cor de fundo. ren1->AddActor2D(pActor); ren1->AddActor(sphere1); ren1->AddActor(sphere2); ren1->AddActor(sphere3); ren1->AddActor(sphere4); ren1->AddActor(sphere5); ren1->AddActor(sphere6); ren1->AddActor(sphere7); ren1->AddActor(sphere8); ren1->AddActor(sphere9); ren1->AddActor(sphere10); ren1->AddActor(sphere11); ren1->AddActor(sphere12); ren1->AddActor(sphere13); ren1->AddActor(sphere14); ren1->AddActor(sphere15); ren1->AddActor(sphere16); ren1->AddActor(sphere17); ren1->AddActor(sphere18); ren1->AddActor(sphere19); ren1->AddActor(sphere20); ren1->AddActor(sphere21);

Page 34: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 32 -

ren1->AddActor(sphere22); ren1->AddActor(sphere23); ren1->AddActor(sphere24); ren1->AddActor(sphere25); ren1->AddActor(sphere26); ren1->AddActor(sphere27); ren1->AddActor(sphere28); ren1->AddActor(sphere29); ren1->AddActor(sphere30); ren1->AddActor(sphere31); ren1->AddActor(sphere32); ren1->AddActor(sphere33); ren1->AddActor(sphere34); ren1->AddActor(sphere35); ren1->AddActor(sphere36); ren1->SetBackground(1, 1, 0.7); renWin->SetSize(400, 200); // Criacao do wireframe (linha da celula unitária) double a,b,c; // Tamanho dos parâmetros da rede a=7.4313; b=14.6278; c=7.7151; static float q[8][3]={{0,0,0}, {a,0,0}, {a,b,0}, {0,b,0}, {0,0,c}, {a,0,c}, {a,b,c}, {0,b,c}}; static vtkIdType pts[6][4]={{0,1,2,3}, {4,5,6,7}, {0,1,5,4}, {1,2,6,5}, {2,3,7,6}, {3,0,4,7}}; vtkPolyData *celula = vtkPolyData::New(); vtkPoints *points = vtkPoints::New(); vtkCellArray *polys=vtkCellArray::New(); int j; for (j=0; j<8; j++) points->InsertPoint(j,q[j]); for (j=0; j<6; j++) polys->InsertNextCell(4,pts[j]); celula->SetPoints(points); points->Delete(); celula->SetPolys(polys); polys->Delete(); // Mapeador da celula vtkPolyDataMapper *celulaMapper = vtkPolyDataMapper::New(); celulaMapper->SetInput(celula); // Criação do actor da celula

Page 35: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 33 -

vtkActor *celulaActor = vtkActor::New(); celulaActor->SetMapper(celulaMapper); celulaActor->GetProperty()->SetRepresentationToWireframe(); ren1->AddActor(celulaActor); celulaMapper->Delete(); // Criação do texto com as direcções segundo xx neste caso é segundo // a direcção do parametro a da celula,b corresponde aos yy e finalmente c aos zz. vtkVectorText *texta=vtkVectorText::New(); texta->SetText("a"); vtkPolyDataMapper *textaMapper=vtkPolyDataMapper::New(); textaMapper->SetInput(texta->GetOutput()); vtkActor *textaActor=vtkActor::New(); textaActor->SetMapper(textaMapper); textaActor->SetPosition(1,0,-0.5); textaActor->SetScale(0.5); ren1->AddActor(textaActor); vtkVectorText *textb=vtkVectorText::New(); textb->SetText("b"); vtkPolyDataMapper *textbMapper=vtkPolyDataMapper::New(); textbMapper->SetInput(textb->GetOutput()); vtkActor *textbActor=vtkActor::New(); textbActor->SetMapper(textbMapper); textbActor->SetPosition(0,1,-0.5); textbActor->SetScale(0.5); ren1->AddActor(textbActor); vtkVectorText *textc=vtkVectorText::New(); textc->SetText("c"); vtkPolyDataMapper *textcMapper=vtkPolyDataMapper::New(); textcMapper->SetInput(textc->GetOutput()); vtkActor *textcActor=vtkActor::New(); textcActor->SetMapper(textcMapper); textcActor->SetPosition(-0.5,0,1); textcActor->SetScale(0.5); ren1->AddActor(textcActor); // Criação dos eixos vtkAxes *axes=vtkAxes::New(); axes->SetOrigin(0,0,0); axes->SetScaleFactor(1); axes->SymmetricOn(); vtkPolyDataMapper *axesMapper=vtkPolyDataMapper::New(); axesMapper->SetInput(axes->GetOutput()); vtkActor *axesActor=vtkActor::New();

Page 36: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 34 -

axesActor->SetMapper(axesMapper); ren1->AddActor(axesActor); axesMapper->Delete(); // Criação da luz no render vtkLight *light = vtkLight::New(); light->SetFocalPoint(1.875,0.6125,0); light->SetPosition(0.875,1.6125,1); ren1->AddLight(light); // Inicializar as interacções iren->Initialize(); iren->Start(); // Apapgar todos os pointers (actores, render, mapeadores, sources, renderwindows, lights, etc.) pText->Delete(); pActor->Delete(); sphere->Delete(); sphereMapper->Delete(); celula->Delete(); sphere1->Delete(); sphere2->Delete(); sphere3->Delete(); sphere4->Delete(); sphere5->Delete(); sphere6->Delete(); sphere7->Delete(); sphere8->Delete(); sphere9->Delete(); sphere10->Delete(); sphere11->Delete(); sphere12->Delete(); sphere13->Delete(); sphere14->Delete(); sphere15->Delete(); sphere16->Delete(); sphere17->Delete(); sphere18->Delete(); sphere19->Delete(); sphere20->Delete(); sphere21->Delete(); sphere22->Delete(); sphere23->Delete(); sphere24->Delete(); sphere25->Delete(); sphere26->Delete(); sphere27->Delete(); sphere28->Delete(); sphere29->Delete(); sphere30->Delete(); sphere31->Delete(); sphere32->Delete(); sphere33->Delete(); sphere34->Delete(); sphere35->Delete();

Page 37: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 35 -

sphere36->Delete(); texta->Delete(); textaMapper->Delete(); textaActor->Delete(); textb->Delete(); textbMapper->Delete(); textbActor->Delete(); textc->Delete(); textcMapper->Delete(); textcActor->Delete(); axesActor->Delete(); axes->Delete(); celulaActor->Delete(); celula->Delete(); light->Delete(); ren1->Delete(); renWin->Delete(); iren->Delete(); return 0; } // No caso de ter sido escolhida a letra M foi escolhida a estrutura magnética // Contem apenas 20 atomos (atomos azuis) com os momentos de spin do sistema if ( util == 'M') { n=0; double phi[21]; double theta[21]; FILE *input; // abertura de ficheiros com direcção e sentido dos spins. if( (input = fopen("angulos.dat", "r")) == NULL) { printf("\nO ficheiro angulos.dt não foi aberto\n"); return 1; } else printf("\nO ficheiro 'angulos.dat' foi aberto\n"); // imprime os dados while (fscanf(input, "%lf %lf\n", &phi[n+1], &theta[n+1]) != EOF) { n++; printf("\n Point %d angulo phi=%lf, teta=%lf",n, phi[n], theta[n]); }

Page 38: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 36 -

// Criação da fonte da secta (source) que é a junção de um // cone numa extremidade de um cilindro vtkArrowSource *arrow = vtkArrowSource::New(); // Mappeador da secta vtkPolyDataMapper *arrowMapper = vtkPolyDataMapper::New(); arrowMapper->SetInput(arrow->GetOutput()); // Criação dos actores sectas (correspondem aos spins): vtkActor *arrowactor1 = vtkActor::New(); arrowactor1->SetMapper(arrowMapper); arrowactor1->SetPosition(x[1]-0.5, y[1], z[1]); arrowactor1->SetScale(2); (arrowactor1->GetProperty())->SetColor(0.5, 0.5, 0.5); arrowactor1->RotateZ(phi[1]); arrowactor1->RotateX(theta[1]); vtkActor *arrowactor2 = vtkActor::New(); arrowactor2->SetMapper(arrowMapper); arrowactor2->SetPosition(x[2]-0.5, y[2], z[2]); arrowactor2->SetScale(2); (arrowactor2->GetProperty())->SetColor(0.5, 0.5, 0.5); arrowactor2->RotateZ(phi[2]); arrowactor2->RotateX(theta[2]); vtkActor *arrowactor3 = vtkActor::New(); arrowactor3->SetMapper(arrowMapper); arrowactor3->SetPosition(x[3]-0.5, y[3], z[3]); arrowactor3->SetScale(2); (arrowactor3->GetProperty())->SetColor(0.5, 0.5, 0.5); arrowactor3->RotateZ(phi[3]); arrowactor3->RotateX(theta[3]); vtkActor *arrowactor4 = vtkActor::New(); arrowactor4->SetMapper(arrowMapper); arrowactor4->SetPosition(x[4]-0.5, y[4], z[4]); arrowactor4->SetScale(2); (arrowactor4->GetProperty())->SetColor(0.5, 0.5, 0.5); arrowactor4->RotateZ(phi[4]); arrowactor4->RotateX(theta[4]); vtkActor *arrowactor5 = vtkActor::New(); arrowactor5->SetMapper(arrowMapper); arrowactor5->SetPosition(x[5]-0.5, y[5], z[5]); arrowactor5->SetScale(2); (arrowactor5->GetProperty())->SetColor(0.5, 0.5, 0.5); arrowactor5->RotateZ(phi[5]); arrowactor5->RotateX(theta[5]); vtkActor *arrowactor6 = vtkActor::New(); arrowactor6->SetMapper(arrowMapper); arrowactor6->SetPosition(x[6]-0.5, y[6], z[6]); arrowactor6->SetScale(2); (arrowactor6->GetProperty())->SetColor(0.5, 0.5, 0.5); arrowactor6->RotateZ(phi[6]); arrowactor6->RotateX(theta[6]);

Page 39: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 37 -

vtkActor *arrowactor7 = vtkActor::New(); arrowactor7->SetMapper(arrowMapper); arrowactor7->SetPosition(x[7]-0.5, y[7], z[7]); arrowactor7->SetScale(2); (arrowactor7->GetProperty())->SetColor(0.5, 0.5, 0.5); arrowactor7->RotateZ(phi[7]); arrowactor7->RotateX(theta[7]); vtkActor *arrowactor8 = vtkActor::New(); arrowactor8->SetMapper(arrowMapper); arrowactor8->SetPosition(x[8]-0.5, y[8], z[8]); arrowactor8->SetScale(2); (arrowactor8->GetProperty())->SetColor(0.5, 0.5, 0.5); arrowactor8->RotateZ(phi[1]); arrowactor8->RotateX(theta[1]); vtkActor *arrowactor9 = vtkActor::New(); arrowactor9->SetMapper(arrowMapper); arrowactor9->SetPosition(x[9]-0.5, y[9], z[9]); arrowactor9->SetScale(2); (arrowactor9->GetProperty())->SetColor(0.5, 0.5, 0.5); arrowactor9->RotateZ(phi[9]); arrowactor9->RotateX(theta[9]); vtkActor *arrowactor10 = vtkActor::New(); arrowactor10->SetMapper(arrowMapper); arrowactor10->SetPosition(x[10]-0.5, y[10], z[10]); arrowactor10->SetScale(2); (arrowactor10->GetProperty())->SetColor(0.5, 0.5, 0.5); arrowactor10->RotateZ(phi[10]); arrowactor10->RotateX(theta[10]); vtkActor *arrowactor11 = vtkActor::New(); arrowactor11->SetMapper(arrowMapper); arrowactor11->SetPosition(x[11]-0.5, y[11], z[11]); arrowactor11->SetScale(2); (arrowactor11->GetProperty())->SetColor(0.5, 0.5, 0.5); arrowactor11->RotateZ(phi[11]); arrowactor11->RotateX(theta[11]); vtkActor *arrowactor12 = vtkActor::New(); arrowactor12->SetMapper(arrowMapper); arrowactor12->SetPosition(x[12]-0.5, y[12], z[12]); arrowactor12->SetScale(2); (arrowactor12->GetProperty())->SetColor(0.5, 0.5, 0.5); arrowactor12->RotateZ(phi[12]); arrowactor12->RotateX(theta[12]); vtkActor *arrowactor13 = vtkActor::New(); arrowactor13->SetMapper(arrowMapper); arrowactor13->SetPosition(x[13]-0.5, y[13], z[13]); arrowactor13->SetScale(2); (arrowactor13->GetProperty())->SetColor(0.5, 0.5, 0.5); arrowactor13->RotateZ(phi[13]); arrowactor13->RotateX(theta[13]); vtkActor *arrowactor14 = vtkActor::New(); arrowactor14->SetMapper(arrowMapper); arrowactor14->SetPosition(x[14]-0.5, y[14], z[14]); arrowactor14->SetScale(2);

Page 40: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 38 -

(arrowactor14->GetProperty())->SetColor(0.5, 0.5, 0.5); arrowactor14->RotateZ(phi[14]); arrowactor14->RotateX(theta[14]); vtkActor *arrowactor15 = vtkActor::New(); arrowactor15->SetMapper(arrowMapper); arrowactor15->SetPosition(x[15]-0.5, y[15], z[15]); arrowactor15->SetScale(2); (arrowactor15->GetProperty())->SetColor(0.5, 0.5, 0.5); arrowactor15->RotateZ(phi[15]); arrowactor15->RotateX(theta[15]); vtkActor *arrowactor16 = vtkActor::New(); arrowactor16->SetMapper(arrowMapper); arrowactor16->SetPosition(x[16]-0.5, y[16], z[16]); arrowactor16->SetScale(2); (arrowactor16->GetProperty())->SetColor(0.5, 0.5, 0.5); arrowactor16->RotateZ(phi[16]); arrowactor16->RotateX(theta[16]); vtkActor *arrowactor17 = vtkActor::New(); arrowactor17->SetMapper(arrowMapper); arrowactor17->SetPosition(x[17]-0.5, y[17], z[17]); arrowactor17->SetScale(2); (arrowactor17->GetProperty())->SetColor(0.5, 0.5, 0.5); arrowactor17->RotateZ(phi[17]); arrowactor17->RotateX(theta[17]); vtkActor *arrowactor18 = vtkActor::New(); arrowactor18->SetMapper(arrowMapper); arrowactor18->SetPosition(x[18]-0.5, y[18], z[18]); arrowactor18->SetScale(2); (arrowactor18->GetProperty())->SetColor(0.5, 0.5, 0.5); arrowactor18->RotateZ(phi[18]); arrowactor18->RotateX(theta[18]); vtkActor *arrowactor19 = vtkActor::New(); arrowactor19->SetMapper(arrowMapper); arrowactor19->SetPosition(x[19]-0.5, y[19], z[19]); arrowactor19->SetScale(2); (arrowactor19->GetProperty())->SetColor(0.5, 0.5, 0.5); arrowactor19->RotateZ(phi[19]); arrowactor19->RotateX(theta[19]); vtkActor *arrowactor20 = vtkActor::New(); arrowactor20->SetMapper(arrowMapper); arrowactor20->SetPosition(x[20]-0.5, y[20], z[20]); arrowactor20->SetScale(2); (arrowactor20->GetProperty())->SetColor(0.5, 0.5, 0.5); arrowactor20->RotateZ(phi[20]); arrowactor20->RotateX(theta[20]); // Criação da esfera como no caso anterior (Source->Mappear->Actor) vtkSphereSource *sphere = vtkSphereSource::New(); sphere->SetThetaResolution(100); sphere->SetPhiResolution(50); vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New(); sphereMapper->SetInput(sphere->GetOutput());

Page 41: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 39 -

vtkActor *sphere1 = vtkActor::New(); sphere1->SetMapper(sphereMapper); sphere1->GetProperty()->SetColor(0,0,1); sphere1->GetProperty()->SetAmbient(0.3); sphere1->GetProperty()->SetDiffuse(0.5); sphere1->GetProperty()->SetSpecular(1.0); sphere1->GetProperty()->SetSpecularPower(20.0); sphere1->AddPosition(x[1],y[1],z[1]); vtkActor *sphere2 = vtkActor::New(); sphere2->SetMapper(sphereMapper); sphere2->GetProperty()->SetColor(0,0,1); sphere2->GetProperty()->SetAmbient(0.3); sphere2->GetProperty()->SetDiffuse(0.5); sphere2->GetProperty()->SetSpecular(1.0); sphere2->GetProperty()->SetSpecularPower(20.0); sphere2->AddPosition(x[2],y[2],z[2]); vtkActor *sphere3 = vtkActor::New(); sphere3->SetMapper(sphereMapper); sphere3->GetProperty()->SetColor(0,0,1); sphere3->GetProperty()->SetAmbient(0.3); sphere3->GetProperty()->SetDiffuse(0.5); sphere3->GetProperty()->SetSpecular(1.0); sphere3->GetProperty()->SetSpecularPower(20.0); sphere3->AddPosition(x[3],y[3],z[3]); vtkActor *sphere4 = vtkActor::New(); sphere4->SetMapper(sphereMapper); sphere4->GetProperty()->SetColor(0,0,1); sphere4->GetProperty()->SetAmbient(0.3); sphere4->GetProperty()->SetDiffuse(0.5); sphere4->GetProperty()->SetSpecular(1.0); sphere4->GetProperty()->SetSpecularPower(20.0); sphere4->AddPosition(x[4],y[4],z[4]); vtkActor *sphere5 = vtkActor::New(); sphere5->SetMapper(sphereMapper); sphere5->GetProperty()->SetColor(0,0,1); sphere5->GetProperty()->SetAmbient(0.3); sphere5->GetProperty()->SetDiffuse(0.5); sphere5->GetProperty()->SetSpecular(1.0); sphere5->GetProperty()->SetSpecularPower(20.0); sphere5->AddPosition(x[5],y[5],z[5]); vtkActor *sphere6 = vtkActor::New(); sphere6->SetMapper(sphereMapper); sphere6->GetProperty()->SetColor(0,0,1); sphere6->GetProperty()->SetAmbient(0.3); sphere6->GetProperty()->SetDiffuse(0.5); sphere6->GetProperty()->SetSpecular(0.5); sphere6->GetProperty()->SetSpecularPower(20.0); sphere6->AddPosition(x[6],y[6],z[6]); vtkActor *sphere7 = vtkActor::New(); sphere7->SetMapper(sphereMapper); sphere7->GetProperty()->SetColor(0,0,1); sphere7->GetProperty()->SetAmbient(0.3); sphere7->GetProperty()->SetDiffuse(0.5); sphere7->GetProperty()->SetSpecular(0.5); sphere7->GetProperty()->SetSpecularPower(20.0);

Page 42: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 40 -

sphere7->AddPosition(x[7],y[7],z[7]); vtkActor *sphere8 = vtkActor::New(); sphere8->SetMapper(sphereMapper); sphere8->GetProperty()->SetColor(0,0,1); sphere8->GetProperty()->SetAmbient(0.3); sphere8->GetProperty()->SetDiffuse(0.5); sphere8->GetProperty()->SetSpecular(0.5); sphere8->GetProperty()->SetSpecularPower(20.0); sphere8->AddPosition(x[8],y[8],z[8]); vtkActor *sphere9 = vtkActor::New(); sphere9->SetMapper(sphereMapper); sphere9->GetProperty()->SetColor(0,0,1); sphere9->GetProperty()->SetAmbient(0.3); sphere9->GetProperty()->SetDiffuse(0.5); sphere9->GetProperty()->SetSpecular(1.0); sphere9->GetProperty()->SetSpecularPower(20.0); sphere9->AddPosition(x[9],y[9],z[9]); vtkActor *sphere10 = vtkActor::New(); sphere10->SetMapper(sphereMapper); sphere10->GetProperty()->SetColor(0,0,1); sphere10->GetProperty()->SetAmbient(0.3); sphere10->GetProperty()->SetDiffuse(0.5); sphere10->GetProperty()->SetSpecular(1.0); sphere10->GetProperty()->SetSpecularPower(20.0); sphere10->AddPosition(x[10],y[10],z[10]); vtkActor *sphere11 = vtkActor::New(); sphere11->SetMapper(sphereMapper); sphere11->GetProperty()->SetColor(0,0,1); sphere11->GetProperty()->SetAmbient(0.3); sphere11->GetProperty()->SetDiffuse(0.5); sphere11->GetProperty()->SetSpecular(1.0); sphere11->GetProperty()->SetSpecularPower(20.0); sphere11->AddPosition(x[11],y[11],z[11]); vtkActor *sphere12 = vtkActor::New(); sphere12->SetMapper(sphereMapper); sphere12->GetProperty()->SetColor(0,0,1); sphere12->GetProperty()->SetAmbient(0.3); sphere12->GetProperty()->SetDiffuse(0.5); sphere12->GetProperty()->SetSpecular(1.0); sphere12->GetProperty()->SetSpecularPower(20.0); sphere12->AddPosition(x[12],y[12],z[12]); vtkActor *sphere13 = vtkActor::New(); sphere13->SetMapper(sphereMapper); sphere13->GetProperty()->SetColor(0,0,1); sphere13->GetProperty()->SetAmbient(0.3); sphere13->GetProperty()->SetDiffuse(0.5); sphere13->GetProperty()->SetSpecular(0.5); sphere13->GetProperty()->SetSpecularPower(5.0); sphere13->AddPosition(x[13],y[13],z[13]); vtkActor *sphere14 = vtkActor::New(); sphere14->SetMapper(sphereMapper); sphere14->GetProperty()->SetColor(0,0,1); sphere14->GetProperty()->SetAmbient(0.3); sphere14->GetProperty()->SetDiffuse(0.5);

Page 43: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 41 -

sphere14->GetProperty()->SetSpecular(0.5); sphere14->GetProperty()->SetSpecularPower(20.0); sphere14->AddPosition(x[14],y[14],z[14]); vtkActor *sphere15 = vtkActor::New(); sphere15->SetMapper(sphereMapper); sphere15->GetProperty()->SetColor(0,0,1); sphere15->GetProperty()->SetAmbient(0.3); sphere15->GetProperty()->SetDiffuse(0.5); sphere15->GetProperty()->SetSpecular(0.5); sphere15->GetProperty()->SetSpecularPower(20.0); sphere15->AddPosition(x[15],y[15],z[15]); vtkActor *sphere16 = vtkActor::New(); sphere16->SetMapper(sphereMapper); sphere16->GetProperty()->SetColor(0,0,1); sphere16->GetProperty()->SetAmbient(0.3); sphere16->GetProperty()->SetDiffuse(0.5); sphere16->GetProperty()->SetSpecular(0.5); sphere16->GetProperty()->SetSpecularPower(20.0); sphere16->AddPosition(x[16],y[16],z[16]); vtkActor *sphere17 = vtkActor::New(); sphere17->SetMapper(sphereMapper); sphere17->GetProperty()->SetColor(0,0,1); sphere17->GetProperty()->SetAmbient(0.3); sphere17->GetProperty()->SetDiffuse(0.5); sphere17->GetProperty()->SetSpecular(1.0); sphere17->GetProperty()->SetSpecularPower(20.0); sphere17->AddPosition(x[17],y[17],z[17]); vtkActor *sphere18 = vtkActor::New(); sphere18->SetMapper(sphereMapper); sphere18->GetProperty()->SetColor(0,0,1); sphere18->GetProperty()->SetAmbient(0.3); sphere18->GetProperty()->SetDiffuse(0.5); sphere18->GetProperty()->SetSpecular(1.0); sphere18->GetProperty()->SetSpecularPower(20.0); sphere18->AddPosition(x[18],y[18],z[18]); vtkActor *sphere19 = vtkActor::New(); sphere19->SetMapper(sphereMapper); sphere19->GetProperty()->SetColor(0,0,1); sphere19->GetProperty()->SetAmbient(0.3); sphere19->GetProperty()->SetDiffuse(0.5); sphere19->GetProperty()->SetSpecular(1.0); sphere19->GetProperty()->SetSpecularPower(20.0); sphere19->AddPosition(x[19],y[19],z[19]); vtkActor *sphere20 = vtkActor::New(); sphere20->SetMapper(sphereMapper); sphere20->GetProperty()->SetColor(0,0,1); sphere20->GetProperty()->SetAmbient(0.3); sphere20->GetProperty()->SetDiffuse(0.5); sphere20->GetProperty()->SetSpecular(1.0); sphere20->GetProperty()->SetSpecularPower(20.0); sphere20->AddPosition(x[20],y[20],z[20]); // Criação de Texto

Page 44: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 42 -

char *text = "Estrutura Magnetica"; vtkTextMapper *pText = vtkTextMapper::New(); pText->SetInput(text); // aceder as propriedades do vtkMapperText vtkTextProperty *propText = pText->GetTextProperty(); propText->SetFontSize(18); propText->SetFontFamilyToArial(); propText->SetColor(1,0,0); propText->BoldOn(); propText->ItalicOff(); propText->ShadowOff(); propText->SetJustificationToLeft(); propText->SetVerticalJustificationToBottom(); // Criação de um actor com o texto vtkActor2D *pActor = vtkActor2D::New(); pActor->SetMapper(pText); pActor->SetPosition(425,650); //Criar um render cena colocar todososactores dentroda cena, //criar uma janela e depois colocar a cena nessa janela. vtkRenderer *ren1 = vtkRenderer::New(); vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->AddRenderer(ren1); vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); iren->SetRenderWindow(renWin); ren1->AddActor2D(pActor); ren1->AddActor(arrowactor1); ren1->AddActor(arrowactor2); ren1->AddActor(arrowactor3); ren1->AddActor(arrowactor4); ren1->AddActor(arrowactor5); ren1->AddActor(arrowactor6); ren1->AddActor(arrowactor7); ren1->AddActor(arrowactor8); ren1->AddActor(arrowactor9); ren1->AddActor(arrowactor10); ren1->AddActor(arrowactor11); ren1->AddActor(arrowactor12); ren1->AddActor(arrowactor13); ren1->AddActor(arrowactor14); ren1->AddActor(arrowactor15); ren1->AddActor(arrowactor16); ren1->AddActor(arrowactor17); ren1->AddActor(arrowactor18); ren1->AddActor(arrowactor19); ren1->AddActor(arrowactor20); ren1->AddActor(sphere1); ren1->AddActor(sphere2); ren1->AddActor(sphere3); ren1->AddActor(sphere4); ren1->AddActor(sphere5);

Page 45: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 43 -

ren1->AddActor(sphere6); ren1->AddActor(sphere7); ren1->AddActor(sphere8); ren1->AddActor(sphere9); ren1->AddActor(sphere10); ren1->AddActor(sphere11); ren1->AddActor(sphere12); ren1->AddActor(sphere13); ren1->AddActor(sphere14); ren1->AddActor(sphere15); ren1->AddActor(sphere16); ren1->AddActor(sphere17); ren1->AddActor(sphere18); ren1->AddActor(sphere19); ren1->AddActor(sphere20); ren1->SetBackground(0.9, 1 , 1); renWin->SetSize(400, 200); //Criação da celula unitária (wireframe), eixos e etiquetaspara os eixos // Igual para o caso anterior double a,b,c; a=7.4313; b=14.6278; c=7.7151; static float q[8][3]={{0,0,0}, {a,0,0}, {a,b,0}, {0,b,0}, {0,0,c}, {a,0,c}, {a,b,c}, {0,b,c}}; static vtkIdType pts[6][4]={{0,1,2,3}, {4,5,6,7}, {0,1,5,4}, {1,2,6,5}, {2,3,7,6}, {3,0,4,7}}; vtkPolyData *celula = vtkPolyData::New(); vtkPoints *points = vtkPoints::New(); vtkCellArray *polys=vtkCellArray::New(); int j; for (j=0; j<8; j++) points->InsertPoint(j,q[j]); for (j=0; j<6; j++) polys->InsertNextCell(4,pts[j]); celula->SetPoints(points); points->Delete(); celula->SetPolys(polys); polys->Delete(); vtkPolyDataMapper *celulaMapper = vtkPolyDataMapper::New(); celulaMapper->SetInput(celula); vtkActor *celulaActor = vtkActor::New(); celulaActor->SetMapper(celulaMapper); celulaActor->GetProperty()->SetRepresentationToWireframe();

Page 46: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 44 -

ren1->AddActor(celulaActor); celulaMapper->Delete(); vtkVectorText *texta=vtkVectorText::New(); texta->SetText("a"); vtkPolyDataMapper *textaMapper=vtkPolyDataMapper::New(); textaMapper->SetInput(texta->GetOutput()); vtkActor *textaActor=vtkActor::New(); textaActor->SetMapper(textaMapper); textaActor->SetPosition(1,0,-0.5); textaActor->SetScale(0.5); ren1->AddActor(textaActor); vtkVectorText *textb=vtkVectorText::New(); textb->SetText("b"); vtkPolyDataMapper *textbMapper=vtkPolyDataMapper::New(); textbMapper->SetInput(textb->GetOutput()); vtkActor *textbActor=vtkActor::New(); textbActor->SetMapper(textbMapper); textbActor->SetPosition(0,1,-0.5); textbActor->SetScale(0.5); ren1->AddActor(textbActor); vtkVectorText *textc=vtkVectorText::New(); textc->SetText("c"); vtkPolyDataMapper *textcMapper=vtkPolyDataMapper::New(); textcMapper->SetInput(textc->GetOutput()); vtkActor *textcActor=vtkActor::New(); textcActor->SetMapper(textcMapper); textcActor->SetPosition(-0.5,0,1); textcActor->SetScale(0.5); ren1->AddActor(textcActor); vtkAxes *axes=vtkAxes::New(); axes->SetOrigin(0,0,0); axes->SetScaleFactor(1); axes->SymmetricOn(); vtkPolyDataMapper *axesMapper=vtkPolyDataMapper::New(); axesMapper->SetInput(axes->GetOutput()); vtkActor *axesActor=vtkActor::New(); axesActor->SetMapper(axesMapper); ren1->AddActor(axesActor); axesMapper->Delete(); // Luz. vtkLight *light = vtkLight::New(); light->SetFocalPoint(1.875,0.6125,0); light->SetPosition(0.875,1.6125,1); ren1->AddLight(light); //inicializar a interacção

Page 47: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 45 -

iren->Initialize(); iren->Start(); //Apagar todos os pointers. pText->Delete(); pActor->Delete(); arrow->Delete(); arrowMapper->Delete(); arrowactor1->Delete(); arrowactor2->Delete(); arrowactor3->Delete(); arrowactor4->Delete(); arrowactor5->Delete(); arrowactor6->Delete(); arrowactor7->Delete(); arrowactor8->Delete(); arrowactor9->Delete(); arrowactor10->Delete(); arrowactor11->Delete(); arrowactor12->Delete(); arrowactor13->Delete(); arrowactor14->Delete(); arrowactor15->Delete(); arrowactor16->Delete(); arrowactor17->Delete(); arrowactor18->Delete(); arrowactor19->Delete(); arrowactor20->Delete(); sphere->Delete(); sphereMapper->Delete(); celula->Delete(); sphere1->Delete(); sphere2->Delete(); sphere3->Delete(); sphere4->Delete(); sphere5->Delete(); sphere6->Delete(); sphere7->Delete(); sphere8->Delete(); sphere9->Delete(); sphere10->Delete(); sphere11->Delete(); sphere12->Delete(); sphere13->Delete(); sphere14->Delete(); sphere15->Delete(); sphere16->Delete(); sphere17->Delete(); sphere18->Delete(); sphere19->Delete(); sphere20->Delete(); axesActor->Delete(); axes->Delete(); texta->Delete(); textaMapper->Delete(); textaActor->Delete();

Page 48: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 46 -

textb->Delete(); textbMapper->Delete(); textbActor->Delete(); textc->Delete(); textcMapper->Delete(); textcActor->Delete(); light->Delete(); ren1->Delete(); renWin->Delete(); iren->Delete(); return 0; } // Neste programa é utilizado a class MyCallback //e pertende simular a transição estrutural do sistema do sistema em estudo if ( util == 'S') { // Novamente fazer po codigo fonte e depois mapperar uma esfera vtkSphereSource *sphere = vtkSphereSource::New(); sphere->SetThetaResolution(100); sphere->SetPhiResolution(50); vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New(); sphereMapper->SetInput(sphere->GetOutput()); //Grupo de actores nas posições dos ficheiros sphere1 = vtkActor::New(); sphere1->SetMapper(sphereMapper); sphere1->GetProperty()->SetColor(0,0,1); sphere1->GetProperty()->SetAmbient(0.3); sphere1->GetProperty()->SetDiffuse(0.5); sphere1->GetProperty()->SetSpecular(1.0); sphere1->GetProperty()->SetSpecularPower(20.0); sphere1->AddPosition(x[1],y[1],z[1]); sphere2 = vtkActor::New(); sphere2->SetMapper(sphereMapper); sphere2->GetProperty()->SetColor(0,0,1); sphere2->GetProperty()->SetAmbient(0.3); sphere2->GetProperty()->SetDiffuse(0.5); sphere2->GetProperty()->SetSpecular(1.0); sphere2->GetProperty()->SetSpecularPower(20.0); sphere2->AddPosition(x[2],y[2],z[2]); sphere3 = vtkActor::New(); sphere3->SetMapper(sphereMapper); sphere3->GetProperty()->SetColor(0,0,1);

Page 49: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 47 -

sphere3->GetProperty()->SetAmbient(0.3); sphere3->GetProperty()->SetDiffuse(0.5); sphere3->GetProperty()->SetSpecular(1.0); sphere3->GetProperty()->SetSpecularPower(20.0); sphere3->AddPosition(x[3],y[3],z[3]); sphere4 = vtkActor::New(); sphere4->SetMapper(sphereMapper); sphere4->GetProperty()->SetColor(0,0,1); sphere4->GetProperty()->SetAmbient(0.3); sphere4->GetProperty()->SetDiffuse(0.5); sphere4->GetProperty()->SetSpecular(1.0); sphere4->GetProperty()->SetSpecularPower(20.0); sphere4->AddPosition(x[4],y[4],z[4]); sphere5 = vtkActor::New(); sphere5->SetMapper(sphereMapper); sphere5->GetProperty()->SetColor(0,0,1); sphere5->GetProperty()->SetAmbient(0.3); sphere5->GetProperty()->SetDiffuse(0.5); sphere5->GetProperty()->SetSpecular(1.0); sphere5->GetProperty()->SetSpecularPower(20.0); sphere5->AddPosition(x[5],y[5],z[5]); sphere6 = vtkActor::New(); sphere6->SetMapper(sphereMapper); sphere6->GetProperty()->SetColor(0,0,1); sphere6->GetProperty()->SetAmbient(0.3); sphere6->GetProperty()->SetDiffuse(0.5); sphere6->GetProperty()->SetSpecular(0.5); sphere6->GetProperty()->SetSpecularPower(20.0); sphere6->AddPosition(x[6],y[6],z[6]); sphere7 = vtkActor::New(); sphere7->SetMapper(sphereMapper); sphere7->GetProperty()->SetColor(0,0,1); sphere7->GetProperty()->SetAmbient(0.3); sphere7->GetProperty()->SetDiffuse(0.5); sphere7->GetProperty()->SetSpecular(0.5); sphere7->GetProperty()->SetSpecularPower(20.0); sphere7->AddPosition(x[7],y[7],z[7]); sphere8 = vtkActor::New(); sphere8->SetMapper(sphereMapper); sphere8->GetProperty()->SetColor(0,0,1); sphere8->GetProperty()->SetAmbient(0.3); sphere8->GetProperty()->SetDiffuse(0.5); sphere8->GetProperty()->SetSpecular(0.5); sphere8->GetProperty()->SetSpecularPower(20.0); sphere8->AddPosition(x[8],y[8],z[8]); sphere9 = vtkActor::New(); sphere9->SetMapper(sphereMapper); sphere9->GetProperty()->SetColor(0,0,1); sphere9->GetProperty()->SetAmbient(0.3); sphere9->GetProperty()->SetDiffuse(0.5); sphere9->GetProperty()->SetSpecular(1.0); sphere9->GetProperty()->SetSpecularPower(20.0); sphere9->AddPosition(x[9],y[9],z[9]); sphere10 = vtkActor::New();

Page 50: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 48 -

sphere10->SetMapper(sphereMapper); sphere10->GetProperty()->SetColor(0,0,1); sphere10->GetProperty()->SetAmbient(0.3); sphere10->GetProperty()->SetDiffuse(0.5); sphere10->GetProperty()->SetSpecular(1.0); sphere10->GetProperty()->SetSpecularPower(20.0); sphere10->AddPosition(x[10],y[10],z[10]); sphere11 = vtkActor::New(); sphere11->SetMapper(sphereMapper); sphere11->GetProperty()->SetColor(0,0,1); sphere11->GetProperty()->SetAmbient(0.3); sphere11->GetProperty()->SetDiffuse(0.5); sphere11->GetProperty()->SetSpecular(1.0); sphere11->GetProperty()->SetSpecularPower(20.0); sphere11->AddPosition(x[11],y[11],z[11]); sphere12 = vtkActor::New(); sphere12->SetMapper(sphereMapper); sphere12->GetProperty()->SetColor(0,0,1); sphere12->GetProperty()->SetAmbient(0.3); sphere12->GetProperty()->SetDiffuse(0.5); sphere12->GetProperty()->SetSpecular(1.0); sphere12->GetProperty()->SetSpecularPower(20.0); sphere12->AddPosition(x[12],y[12],z[12]); sphere13 = vtkActor::New(); sphere13->SetMapper(sphereMapper); sphere13->GetProperty()->SetColor(0,0,1); sphere13->GetProperty()->SetAmbient(0.3); sphere13->GetProperty()->SetDiffuse(0.5); sphere13->GetProperty()->SetSpecular(0.5); sphere13->GetProperty()->SetSpecularPower(5.0); sphere13->AddPosition(x[13],y[13],z[13]); sphere14 = vtkActor::New(); sphere14->SetMapper(sphereMapper); sphere14->GetProperty()->SetColor(0,0,1); sphere14->GetProperty()->SetAmbient(0.3); sphere14->GetProperty()->SetDiffuse(0.5); sphere14->GetProperty()->SetSpecular(0.5); sphere14->GetProperty()->SetSpecularPower(20.0); sphere14->AddPosition(x[14],y[14],z[14]); sphere15 = vtkActor::New(); sphere15->SetMapper(sphereMapper); sphere15->GetProperty()->SetColor(0,0,1); sphere15->GetProperty()->SetAmbient(0.3); sphere15->GetProperty()->SetDiffuse(0.5); sphere15->GetProperty()->SetSpecular(0.5); sphere15->GetProperty()->SetSpecularPower(20.0); sphere15->AddPosition(x[15],y[15],z[15]); sphere16 = vtkActor::New(); sphere16->SetMapper(sphereMapper); sphere16->GetProperty()->SetColor(0,0,1); sphere16->GetProperty()->SetAmbient(0.3); sphere16->GetProperty()->SetDiffuse(0.5); sphere16->GetProperty()->SetSpecular(0.5); sphere16->GetProperty()->SetSpecularPower(20.0); sphere16->AddPosition(x[16],y[16],z[16]);

Page 51: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 49 -

sphere17 = vtkActor::New(); sphere17->SetMapper(sphereMapper); sphere17->GetProperty()->SetColor(0,0,1); sphere17->GetProperty()->SetAmbient(0.3); sphere17->GetProperty()->SetDiffuse(0.5); sphere17->GetProperty()->SetSpecular(1.0); sphere17->GetProperty()->SetSpecularPower(20.0); sphere17->AddPosition(x[17],y[17],z[17]); sphere18 = vtkActor::New(); sphere18->SetMapper(sphereMapper); sphere18->GetProperty()->SetColor(0,0,1); sphere18->GetProperty()->SetAmbient(0.3); sphere18->GetProperty()->SetDiffuse(0.5); sphere18->GetProperty()->SetSpecular(1.0); sphere18->GetProperty()->SetSpecularPower(20.0); sphere18->AddPosition(x[18],y[18],z[18]); sphere19 = vtkActor::New(); sphere19->SetMapper(sphereMapper); sphere19->GetProperty()->SetColor(0,0,1); sphere19->GetProperty()->SetAmbient(0.3); sphere19->GetProperty()->SetDiffuse(0.5); sphere19->GetProperty()->SetSpecular(1.0); sphere19->GetProperty()->SetSpecularPower(20.0); sphere19->AddPosition(x[19],y[19],z[19]); sphere20 = vtkActor::New(); sphere20->SetMapper(sphereMapper); sphere20->GetProperty()->SetColor(0,0,1); sphere20->GetProperty()->SetAmbient(0.3); sphere20->GetProperty()->SetDiffuse(0.5); sphere20->GetProperty()->SetSpecular(1.0); sphere20->GetProperty()->SetSpecularPower(20.0); sphere20->AddPosition(x[20],y[20],z[20]); sphere21 = vtkActor::New(); sphere21->SetMapper(sphereMapper); sphere21->GetProperty()->SetColor(1,0,0); sphere21->GetProperty()->SetAmbient(0.3); sphere21->GetProperty()->SetDiffuse(0.5); sphere21->GetProperty()->SetSpecular(1.0); sphere21->GetProperty()->SetSpecularPower(20.0); sphere21->AddPosition(x[21],y[21],z[21]); sphere22 = vtkActor::New(); sphere22->SetMapper(sphereMapper); sphere22->GetProperty()->SetColor(1,0,0); sphere22->GetProperty()->SetAmbient(0.3); sphere22->GetProperty()->SetDiffuse(0.5); sphere22->GetProperty()->SetSpecular(1.0); sphere22->GetProperty()->SetSpecularPower(20.0); sphere22->AddPosition(x[22],y[22],z[22]); sphere23 = vtkActor::New(); sphere23->SetMapper(sphereMapper); sphere23->GetProperty()->SetColor(0,1,0); sphere23->GetProperty()->SetAmbient(0.3); sphere23->GetProperty()->SetDiffuse(0.5);

Page 52: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 50 -

sphere23->GetProperty()->SetSpecular(1.0); sphere23->GetProperty()->SetSpecularPower(20.0); sphere23->AddPosition(x[23],y[23],z[23]); sphere24 = vtkActor::New(); sphere24->SetMapper(sphereMapper); sphere24->GetProperty()->SetColor(0,1,0); sphere24->GetProperty()->SetAmbient(0.3); sphere24->GetProperty()->SetDiffuse(0.5); sphere24->GetProperty()->SetSpecular(1.0); sphere24->GetProperty()->SetSpecularPower(20.0); sphere24->AddPosition(x[24],y[24],z[24]); sphere25 = vtkActor::New(); sphere25->SetMapper(sphereMapper); sphere25->GetProperty()->SetColor(0,1,0); sphere25->GetProperty()->SetAmbient(0.3); sphere25->GetProperty()->SetDiffuse(0.5); sphere25->GetProperty()->SetSpecular(0.5); sphere25->GetProperty()->SetSpecularPower(20.0); sphere25->AddPosition(x[25],y[25],z[25]); sphere26 = vtkActor::New(); sphere26->SetMapper(sphereMapper); sphere26->GetProperty()->SetColor(0,1,0); sphere26->GetProperty()->SetAmbient(0.3); sphere26->GetProperty()->SetDiffuse(0.3); sphere26->GetProperty()->SetSpecular(0.5); sphere26->GetProperty()->SetSpecularPower(20.0); sphere26->AddPosition(x[26],y[26],z[26]); sphere27 = vtkActor::New(); sphere27->SetMapper(sphereMapper); sphere27->GetProperty()->SetColor(1,0,0); sphere27->GetProperty()->SetAmbient(0.3); sphere27->GetProperty()->SetDiffuse(0.3); sphere27->GetProperty()->SetSpecular(0.5); sphere27->GetProperty()->SetSpecularPower(20.0); sphere27->AddPosition(x[27],y[27],z[27]); sphere28 = vtkActor::New(); sphere28->SetMapper(sphereMapper); sphere28->GetProperty()->SetColor(1,0,0); sphere28->GetProperty()->SetAmbient(0.3); sphere28->GetProperty()->SetDiffuse(0.3); sphere28->GetProperty()->SetSpecular(0.5); sphere28->GetProperty()->SetSpecularPower(20.0); sphere28->AddPosition(x[28],y[28],z[28]); sphere29 = vtkActor::New(); sphere29->SetMapper(sphereMapper); sphere29->GetProperty()->SetColor(1,0,0); sphere29->GetProperty()->SetAmbient(0.3); sphere29->GetProperty()->SetDiffuse(0.5); sphere29->GetProperty()->SetSpecular(1.0); sphere29->GetProperty()->SetSpecularPower(20.0); sphere29->AddPosition(x[29],y[29],z[29]); sphere30 = vtkActor::New(); sphere30->SetMapper(sphereMapper); sphere30->GetProperty()->SetColor(1,0,0);

Page 53: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 51 -

sphere30->GetProperty()->SetAmbient(0.3); sphere30->GetProperty()->SetDiffuse(0.5); sphere30->GetProperty()->SetSpecular(1.0); sphere30->GetProperty()->SetSpecularPower(20.0); sphere30->AddPosition(x[30],y[30],z[30]); sphere31 = vtkActor::New(); sphere31->SetMapper(sphereMapper); sphere31->GetProperty()->SetColor(0,1,0); sphere31->GetProperty()->SetAmbient(0.3); sphere31->GetProperty()->SetDiffuse(0.5); sphere31->GetProperty()->SetSpecular(1.0); sphere31->GetProperty()->SetSpecularPower(20.0); sphere31->AddPosition(x[31],y[31],z[31]); sphere32 = vtkActor::New(); sphere32->SetMapper(sphereMapper); sphere32->GetProperty()->SetColor(0,1,0); sphere32->GetProperty()->SetAmbient(0.3); sphere32->GetProperty()->SetDiffuse(0.5); sphere32->GetProperty()->SetSpecular(1.0); sphere32->GetProperty()->SetSpecularPower(20.0); sphere32->AddPosition(x[32],y[32],z[32]); sphere33 = vtkActor::New(); sphere33->SetMapper(sphereMapper); sphere33->GetProperty()->SetColor(0,1,0); sphere33->GetProperty()->SetAmbient(0.3); sphere33->GetProperty()->SetDiffuse(0.5); sphere33->GetProperty()->SetSpecular(0.5); sphere33->GetProperty()->SetSpecularPower(20.0); sphere33->AddPosition(x[33],y[33],z[33]); sphere34 = vtkActor::New(); sphere34->SetMapper(sphereMapper); sphere34->GetProperty()->SetColor(0,1,0); sphere34->GetProperty()->SetAmbient(0.3); sphere34->GetProperty()->SetDiffuse(0.5); sphere34->GetProperty()->SetSpecular(0.5); sphere34->GetProperty()->SetSpecularPower(20.0); sphere34->AddPosition(x[34],y[34],z[34]); sphere35 = vtkActor::New(); sphere35->SetMapper(sphereMapper); sphere35->GetProperty()->SetColor(1,0,0); sphere35->GetProperty()->SetAmbient(0.3); sphere35->GetProperty()->SetDiffuse(0.5); sphere35->GetProperty()->SetSpecular(0.5); sphere35->GetProperty()->SetSpecularPower(20.0); sphere35->AddPosition(x[35],y[35],z[35]); sphere36 = vtkActor::New(); sphere36->SetMapper(sphereMapper); sphere36->GetProperty()->SetColor(1,0,0); sphere36->GetProperty()->SetAmbient(0.3); sphere36->GetProperty()->SetDiffuse(0.5); sphere36->GetProperty()->SetSpecular(0.5); sphere36->GetProperty()->SetSpecularPower(20.0); sphere36->AddPosition(x[36],y[36],z[36]); // Criação do Render

Page 54: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 52 -

ren1 = vtkRenderer::New(); vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->AddRenderer(ren1); // Interação vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); iren->SetRenderWindow(renWin); //Criação dos eixos (ver a trás) vtkAxes *axes=vtkAxes::New(); axes->SetOrigin(0,0,0); axes->SetScaleFactor(1); axes->SymmetricOn(); vtkPolyDataMapper *axesMapper=vtkPolyDataMapper::New(); axesMapper->SetInput(axes->GetOutput()); vtkActor *axesActor=vtkActor::New(); axesActor->SetMapper(axesMapper); ren1->AddActor(axesActor); axesMapper->Delete(); // Texto char *text = "Transição Estrutural"; vtkTextMapper *pText = vtkTextMapper::New(); pText->SetInput(text); vtkTextProperty *propText = pText->GetTextProperty(); propText->SetFontSize(18); propText->SetFontFamilyToArial(); propText->SetColor(0,0,1); propText->BoldOn(); propText->ItalicOff(); propText->ShadowOff(); propText->SetJustificationToLeft(); propText->SetVerticalJustificationToBottom(); vtkActor2D *pActor = vtkActor2D::New(); pActor->SetMapper(pText); pActor->SetPosition(420,650); //adicionar actores ao render ren1->AddActor2D(pActor); ren1->AddActor(sphere1); ren1->AddActor(sphere2); ren1->AddActor(sphere3); ren1->AddActor(sphere4); ren1->AddActor(sphere5); ren1->AddActor(sphere6);

Page 55: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 53 -

ren1->AddActor(sphere7); ren1->AddActor(sphere8); ren1->AddActor(sphere9); ren1->AddActor(sphere10); ren1->AddActor(sphere11); ren1->AddActor(sphere12); ren1->AddActor(sphere13); ren1->AddActor(sphere14); ren1->AddActor(sphere15); ren1->AddActor(sphere16); ren1->AddActor(sphere17); ren1->AddActor(sphere18); ren1->AddActor(sphere19); ren1->AddActor(sphere20); ren1->AddActor(sphere21); ren1->AddActor(sphere22); ren1->AddActor(sphere23); ren1->AddActor(sphere24); ren1->AddActor(sphere25); ren1->AddActor(sphere26); ren1->AddActor(sphere27); ren1->AddActor(sphere28); ren1->AddActor(sphere29); ren1->AddActor(sphere30); ren1->AddActor(sphere31); ren1->AddActor(sphere32); ren1->AddActor(sphere33); ren1->AddActor(sphere34); ren1->AddActor(sphere35); ren1->AddActor(sphere36); //Fazer etiquetas dos eixos (ver a trás) vtkVectorText *texta=vtkVectorText::New(); texta->SetText("a"); vtkPolyDataMapper *textaMapper=vtkPolyDataMapper::New(); textaMapper->SetInput(texta->GetOutput()); vtkActor *textaActor=vtkActor::New(); textaActor->SetMapper(textaMapper); textaActor->SetPosition(1,0,-0.5); textaActor->SetScale(0.5); textaActor->GetProperty()->SetColor(1,0,0); ren1->AddActor(textaActor); vtkVectorText *textb=vtkVectorText::New(); textb->SetText("b"); vtkPolyDataMapper *textbMapper=vtkPolyDataMapper::New(); textbMapper->SetInput(textb->GetOutput()); vtkActor *textbActor=vtkActor::New(); textbActor->SetMapper(textbMapper); textbActor->SetPosition(0,1,-0.5); textbActor->SetScale(0.5); textbActor->GetProperty()->SetColor(1,0,0); ren1->AddActor(textbActor); vtkVectorText *textc=vtkVectorText::New();

Page 56: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 54 -

textc->SetText("c"); vtkPolyDataMapper *textcMapper=vtkPolyDataMapper::New(); textcMapper->SetInput(textc->GetOutput()); vtkActor *textcActor=vtkActor::New(); textcActor->SetMapper(textcMapper); textcActor->SetPosition(-0.5,0,1); textcActor->SetScale(0.5); textcActor->GetProperty()->SetColor(1,0,0); ren1->AddActor(textcActor); ren1->SetBackground(0.9, 0.9, 0.9); renWin->SetSize(400, 400); renWin->Render(); // cria evento para timer. // O intervalo de chamada e controlado pelo sistema operativo // cabendo a funcao chamada verificar se o tempo pretendido passou vtkMyCallback *mo1 = vtkMyCallback::New(); iren->CreateTimer(VTKI_TIMER_FIRST); iren->AddObserver(vtkCommand::TimerEvent, mo1, 2.0); timeLastCall = timeGetTime(); //Inicializao sistema iren->Start(); //Caixa de reciclagem sphere->Delete(); sphereMapper->Delete(); sphere1->Delete(); sphere2->Delete(); sphere3->Delete(); sphere4->Delete(); sphere5->Delete(); sphere6->Delete(); sphere7->Delete(); sphere8->Delete(); sphere9->Delete(); sphere10->Delete(); sphere11->Delete(); sphere12->Delete(); sphere13->Delete(); sphere14->Delete(); sphere15->Delete(); sphere16->Delete(); sphere17->Delete(); sphere18->Delete(); sphere19->Delete(); sphere20->Delete();

Page 57: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 55 -

sphere21->Delete(); sphere22->Delete(); sphere23->Delete(); sphere24->Delete(); sphere25->Delete(); sphere26->Delete(); sphere27->Delete(); sphere28->Delete(); sphere29->Delete(); sphere30->Delete(); sphere31->Delete(); sphere32->Delete(); sphere33->Delete(); sphere34->Delete(); sphere35->Delete(); sphere36->Delete(); axesActor->Delete(); axes->Delete(); texta->Delete(); textaMapper->Delete(); textaActor->Delete(); textb->Delete(); textbMapper->Delete(); textbActor->Delete(); textc->Delete(); textcMapper->Delete(); textcActor->Delete(); ren1->Delete(); renWin->Delete(); iren->Delete(); return 0; } // No caso de ser seleccionado o H o programa o que faz é cria duas janelas // e em cada uma delas representa uma figura com apenas um plano // de atomos de Tb com as duas direcções dos spins a T=2K e T=85K. // Esteprograma foi feito assim para tirar partido das potencialidades do VTk e poder // comparar os resultados obtidos // Existe muitarepetição de processosa unica diferença équetemos dois render edois render windows if ( util == 'H') { n = 0; while (fscanf(input, "%s %lf %lf %lf %lf\n",&nome, &x[n+1], &y[n+1], &z[n+1], &r) != EOF) {

Page 58: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 56 -

n++; printf("\n Point %d coords nome=%s, x=%lf, y=%lf, z=%lf r=%lf", n, nome, x[n], y[n], z[n], r); } n=0; double phi[21]; double theta[21]; if( (input = fopen("angulos.dat", "r")) == NULL) { printf("\nThe file 'angulos.dat was not opened\n"); return 1; } else printf("\nThe file 'angulos.dat' was opened\n"); while (fscanf(input, "%lf %lf\n", &phi[n+1], &theta[n+1]) != EOF) { n++; printf("\n Point %d angulo phi=%lf, theta=%lf",n, phi[n], theta[n]); } n=0; double phiT[21]; double thetaT[21]; // FILE *input; if( (input = fopen("angulosT.dat", "r")) == NULL) { printf("\nThe file 'angulosT.dat was not opened\n"); return 1; } else printf("\nThe file 'angulosT.dat' was opened\n"); while (fscanf(input, "%lf %lf\n", &phiT[n+1], &thetaT[n+1]) != EOF) { n++; printf("\n Point %d angulo Tsr phi=%lf, theta=%lf",n, phiT[n], thetaT[n]); }

Page 59: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 57 -

vtkArrowSource *arrow = vtkArrowSource::New(); vtkPolyDataMapper *arrowMapper = vtkPolyDataMapper::New(); arrowMapper->SetInput(arrow->GetOutput()); vtkActor *arrowactor1 = vtkActor::New(); arrowactor1->SetMapper(arrowMapper); arrowactor1->SetPosition(x[1]-0.5, y[1], z[1]); arrowactor1->SetScale(2); (arrowactor1->GetProperty())->SetColor(0.5, 0.5, 0.5); arrowactor1->RotateY(phi[1]); arrowactor1->RotateX(theta[1]); vtkActor *arrowactor2 = vtkActor::New(); arrowactor2->SetMapper(arrowMapper); arrowactor2->SetPosition(x[2]-0.5, y[2], z[2]); arrowactor2->SetScale(2); (arrowactor2->GetProperty())->SetColor(0.5, 0.5, 0.5); arrowactor2->RotateY(phi[2]); arrowactor2->RotateX(theta[2]); vtkActor *arrowactor3 = vtkActor::New(); arrowactor3->SetMapper(arrowMapper); arrowactor3->SetPosition(x[3]-0.5, y[3], z[3]); arrowactor3->SetScale(2); (arrowactor3->GetProperty())->SetColor(0.5, 0.5, 0.5); arrowactor3->RotateY(phi[3]); arrowactor3->RotateX(theta[3]); vtkActor *arrowactor4 = vtkActor::New(); arrowactor4->SetMapper(arrowMapper); arrowactor4->SetPosition(x[4]-0.5, y[4], z[4]); arrowactor4->SetScale(2); (arrowactor4->GetProperty())->SetColor(0.5, 0.5, 0.5); arrowactor4->RotateY(phi[4]); arrowactor4->RotateX(theta[4]); vtkActor *arrowactor1T = vtkActor::New(); arrowactor1T->SetMapper(arrowMapper); arrowactor1T->SetPosition(x[1]-0.5, y[1]-0.2, z[1]+0.2); arrowactor1T->SetScale(2); (arrowactor1T->GetProperty())->SetColor(0.5, 0.5, 0.5); arrowactor1T->RotateY(phiT[1]); arrowactor1T->RotateX(thetaT[1]); vtkActor *arrowactor2T = vtkActor::New(); arrowactor2T->SetMapper(arrowMapper); arrowactor2T->SetPosition(x[2]-0.5, y[2]-0.2, z[2]+0.2); arrowactor2T->SetScale(2); (arrowactor2T->GetProperty())->SetColor(0.5, 0.5, 0.5); arrowactor2T->RotateY(phiT[2]); arrowactor2T->RotateX(thetaT[2]);

Page 60: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 58 -

vtkActor *arrowactor3T = vtkActor::New(); arrowactor3T->SetMapper(arrowMapper); arrowactor3T->SetPosition(x[3]-0.5, y[3]-0.2, z[3]+0.2); arrowactor3T->SetScale(2); (arrowactor3T->GetProperty())->SetColor(0.5, 0.5, 0.5); arrowactor3T->RotateY(phiT[3]); arrowactor3T->RotateX(thetaT[3]); vtkActor *arrowactor4T = vtkActor::New(); arrowactor4T->SetMapper(arrowMapper); arrowactor4T->SetPosition(x[4]-0.5, y[4]-0.2, z[4]+0.2); arrowactor4T->SetScale(2); (arrowactor4T->GetProperty())->SetColor(0.5, 0.5, 0.5); arrowactor4T->RotateY(phiT[4]); arrowactor4T->RotateX(thetaT[4]); vtkSphereSource *sphere = vtkSphereSource::New(); sphere->SetThetaResolution(100); sphere->SetPhiResolution(50); vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New(); sphereMapper->SetInput(sphere->GetOutput()); vtkActor *sphere1 = vtkActor::New(); sphere1->SetMapper(sphereMapper); sphere1->GetProperty()->SetColor(0,0,1); sphere1->GetProperty()->SetAmbient(0.3); sphere1->GetProperty()->SetDiffuse(0.5); sphere1->GetProperty()->SetSpecular(1.0); sphere1->GetProperty()->SetSpecularPower(20.0); sphere1->AddPosition(x[1],y[1],z[1]); vtkActor *sphere2 = vtkActor::New(); sphere2->SetMapper(sphereMapper); sphere2->GetProperty()->SetColor(0,0,1); sphere2->GetProperty()->SetAmbient(0.3); sphere2->GetProperty()->SetDiffuse(0.5); sphere2->GetProperty()->SetSpecular(1.0); sphere2->GetProperty()->SetSpecularPower(20.0); sphere2->AddPosition(x[2],y[2],z[2]); vtkActor *sphere3 = vtkActor::New(); sphere3->SetMapper(sphereMapper); sphere3->GetProperty()->SetColor(0,0,1); sphere3->GetProperty()->SetAmbient(0.3); sphere3->GetProperty()->SetDiffuse(0.5); sphere3->GetProperty()->SetSpecular(1.0); sphere3->GetProperty()->SetSpecularPower(20.0); sphere3->AddPosition(x[3],y[3],z[3]); vtkActor *sphere4 = vtkActor::New(); sphere4->SetMapper(sphereMapper); sphere4->GetProperty()->SetColor(0,0,1); sphere4->GetProperty()->SetAmbient(0.3); sphere4->GetProperty()->SetDiffuse(0.5);

Page 61: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 59 -

sphere4->GetProperty()->SetSpecular(1.0); sphere4->GetProperty()->SetSpecularPower(20.0); sphere4->AddPosition(x[4],y[4],z[4]); vtkAxes *axes=vtkAxes::New(); axes->SetOrigin(0,0,0); axes->SetScaleFactor(1); axes->SymmetricOn(); vtkPolyDataMapper *axesMapper=vtkPolyDataMapper::New(); axesMapper->SetInput(axes->GetOutput()); vtkActor *axesActor=vtkActor::New(); axesActor->SetMapper(axesMapper); axesMapper->Delete(); char *text = "T = 2 K"; vtkTextMapper *pText = vtkTextMapper::New(); pText->SetInput(text); vtkTextProperty *propText = pText->GetTextProperty(); propText->SetFontSize(18); propText->SetFontFamilyToArial(); propText->SetColor(0,0,1); propText->BoldOn(); propText->ItalicOff(); propText->ShadowOff(); propText->SetJustificationToLeft(); propText->SetVerticalJustificationToBottom(); vtkActor2D *pActor = vtkActor2D::New(); pActor->SetMapper(pText); pActor->SetPosition(150,250); char *text2 = "T = 85 K"; vtkTextMapper *pText2 = vtkTextMapper::New(); pText2->SetInput(text2); vtkTextProperty *propText2 = pText->GetTextProperty(); propText2->SetFontSize(18); propText2->SetFontFamilyToArial(); propText2->SetColor(0,0,1); propText2->BoldOn(); propText2->ItalicOff(); propText2->ShadowOff(); propText2->SetJustificationToLeft(); propText2->SetVerticalJustificationToBottom(); vtkActor2D *pActor2 = vtkActor2D::New(); pActor2->SetMapper(pText2); pActor2->SetPosition(150,250); vtkRenderer *ren1 = vtkRenderer::New();

Page 62: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 60 -

ren1->AddActor(pActor); ren1->AddActor(sphere1); ren1->AddActor(sphere2); ren1->AddActor(sphere3); ren1->AddActor(sphere4); ren1->AddActor(arrowactor1); ren1->AddActor(arrowactor2); ren1->AddActor(arrowactor3); ren1->AddActor(arrowactor4); ren1->AddActor(axesActor); ren1->SetBackground(1,1,1); // Activação de uma camera na posição (0,10,0) para vermos os // atomos no plano x,z e componto focal na origem ren1->GetActiveCamera()->SetFocalPoint(0,0,0); ren1->GetActiveCamera()->SetPosition(0,10,0); ren1->ResetCamera(); ren1->GetActiveCamera()->SetParallelScale(5); vtkRenderer *ren2 = vtkRenderer::New(); ren2->AddActor(pActor2); ren2->AddActor(sphere1); ren2->AddActor(sphere2); ren2->AddActor(sphere3); ren2->AddActor(sphere4); ren2->AddActor(arrowactor1T); ren2->AddActor(arrowactor2T); ren2->AddActor(arrowactor3T); ren2->AddActor(arrowactor4T); ren2->AddActor(axesActor); ren2->SetBackground(0.9,0.9,0.9); ren2->GetActiveCamera()->SetFocalPoint(0,0,0); ren2->GetActiveCamera()->SetPosition(0,10,0); ren2->ResetCamera(); ren2->GetActiveCamera()->SetParallelScale(5); vtkVectorText *texta=vtkVectorText::New(); texta->SetText("a"); vtkPolyDataMapper *textaMapper=vtkPolyDataMapper::New(); textaMapper->SetInput(texta->GetOutput()); vtkActor *textaActor=vtkActor::New(); textaActor->SetMapper(textaMapper); textaActor->SetPosition(1,0,-0.5); textaActor->SetScale(0.5); textaActor->GetProperty()->SetColor(1,0,0); ren1->AddActor(textaActor); ren2->AddActor(textaActor); vtkVectorText *textb=vtkVectorText::New(); textb->SetText("b"); vtkPolyDataMapper *textbMapper=vtkPolyDataMapper::New();

Page 63: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 61 -

textbMapper->SetInput(textb->GetOutput()); vtkActor *textbActor=vtkActor::New(); textbActor->SetMapper(textbMapper); textbActor->SetPosition(0,1,-0.5); textbActor->SetScale(0.5); textbActor->GetProperty()->SetColor(1,0,0); ren1->AddActor(textbActor); ren2->AddActor(textbActor); vtkVectorText *textc=vtkVectorText::New(); textc->SetText("c"); vtkPolyDataMapper *textcMapper=vtkPolyDataMapper::New(); textcMapper->SetInput(textc->GetOutput()); vtkActor *textcActor=vtkActor::New(); textcActor->SetMapper(textcMapper); textcActor->SetPosition(-0.5,0,1); textcActor->SetScale(0.5); textcActor->GetProperty()->SetColor(1,0,0); ren1->AddActor(textcActor); ren2->AddActor(textcActor); vtkRenderWindow *renWin1 = vtkRenderWindow::New(); renWin1->AddRenderer(ren1); vtkRenderWindow *renWin2 = vtkRenderWindow::New(); renWin2->AddRenderer(ren2); vtkRenderWindowInteractor *iren1 = vtkRenderWindowInteractor::New(); iren1->SetRenderWindow(renWin1); vtkRenderWindowInteractor *iren2 = vtkRenderWindowInteractor::New(); iren2->SetRenderWindow(renWin2); renWin1->Render(); renWin2->Render(); iren1->Start(); sphere->Delete(); sphereMapper ->Delete(); sphere1->Delete(); sphere2->Delete(); sphere3->Delete(); sphere4->Delete(); arrowactor1->Delete(); arrowactor2->Delete(); arrowactor3->Delete(); arrowactor4->Delete(); arrowactor1T->Delete(); arrowactor2T->Delete(); arrowactor3T->Delete(); arrowactor4T->Delete(); axesActor->Delete(); axes->Delete();

Page 64: Visualização da estrutura cristalina e magnéticatavares/ensino/VISCI/Trabalhos...Visualização da estrutura cristalina e magnética utilizando o VTK - 9 - b. vtkCellArray – Classe

Visualização da estrutura cristalina e magnética utilizando o VTK

- 62 -

texta->Delete(); textaMapper->Delete(); textaActor->Delete(); textb->Delete(); textbMapper->Delete(); textbActor->Delete(); textc->Delete(); textcMapper->Delete(); textcActor->Delete(); ren1->Delete(); ren2->Delete(); renWin1->Delete(); renWin2->Delete(); iren1->Delete(); iren2->Delete(); return 0; } // No caso de esolher outra opção este programa avisao utilizadorquenão escolheu bem // então acaba o programa if ( util != 'H' && util != 'S' && util != 'M' && util != 'C') { printf ("\n\n Voce nao escolheu nenhuma das opcoes dadas\n"); printf ("\n\n O programa desliga-se automaticamente volte a tentar por favor\n"); printf ("\n\n para isso carregue em qualquer tecla \n"); } }