Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
VTK Examples
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VTK
VTK Examples
Commits
6631cd1d
Commit
6631cd1d
authored
5 years ago
by
Bharatesh Chakravarthi S B
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Create TexturedSphere.java
Former-commit-id:
8e3c35df
parent
20b0ca76
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Java/Texture/TexturedSphere.java
+108
-0
108 additions, 0 deletions
src/Java/Texture/TexturedSphere.java
with
108 additions
and
0 deletions
src/Java/Texture/TexturedSphere.java
0 → 100644
+
108
−
0
View file @
6631cd1d
import
vtk.vtkActor
;
import
vtk.vtkNamedColors
;
import
vtk.vtkNativeLibrary
;
import
vtk.vtkPolyDataMapper
;
import
vtk.vtkRenderWindow
;
import
vtk.vtkRenderWindowInteractor
;
import
vtk.vtkRenderer
;
import
vtk.vtkTexturedSphereSource
;
import
vtk.vtkImageReader2Factory
;
import
vtk.vtkTexture
;
import
vtk.vtkImageReader2
;
import
vtk.vtkTransformTextureCoords
;
public
class
TexturedSphere
{
// -----------------------------------------------------------------
// Load VTK library and print which library was not properly loaded
static
{
if
(!
vtkNativeLibrary
.
LoadAllNativeLibraries
())
{
for
(
vtkNativeLibrary
lib
:
vtkNativeLibrary
.
values
())
{
if
(!
lib
.
IsLoaded
())
{
System
.
out
.
println
(
lib
.
GetLibraryName
()
+
" not loaded"
);
}
}
}
vtkNativeLibrary
.
DisableOutputWindow
(
null
);
}
// -----------------------------------------------------------------
public
static
void
main
(
String
args
[])
{
//parse command line arguments
if
(
args
.
length
<
2
)
{
System
.
err
.
println
(
"Usage: java -classpath ... Filename(.png) translate e.g earthTexture.png 0 "
);
return
;
}
double
translate
[]
=
new
double
[
3
];
String
inputFilename
=
args
[
0
];
if
(
args
.
length
>
2
)
{
translate
[
0
]
=
Double
.
parseDouble
(
args
[
1
]);
}
else
{
translate
[
0
]
=
0.0
;
}
translate
[
1
]
=
0.0
;
translate
[
2
]
=
0.0
;
System
.
out
.
print
(
translate
[
0
]
+
" "
+
translate
[
1
]
+
" "
+
translate
[
2
]
+
"\n"
);
vtkNamedColors
colors
=
new
vtkNamedColors
();
double
Bgcolor
[]
=
new
double
[
4
];
colors
.
GetColor
(
"SteelBlue"
,
Bgcolor
);
// Create a sphere with texture coordinates
vtkTexturedSphereSource
source
=
new
vtkTexturedSphereSource
();
source
.
SetPhiResolution
(
40
);
source
.
SetThetaResolution
(
40
);
// Read texture file
vtkImageReader2Factory
readerFactory
=
new
vtkImageReader2Factory
();
vtkImageReader2
imageReader
=
new
vtkImageReader2
();
imageReader
=
readerFactory
.
CreateImageReader2
(
inputFilename
);
imageReader
.
SetFileName
(
inputFilename
);
// Create texture
vtkTexture
texture
=
new
vtkTexture
();
texture
.
SetInputConnection
(
imageReader
.
GetOutputPort
());
vtkTransformTextureCoords
transformTexture
=
new
vtkTransformTextureCoords
();
transformTexture
.
SetInputConnection
(
source
.
GetOutputPort
());
transformTexture
.
SetPosition
(
translate
);
vtkPolyDataMapper
mapper
=
new
vtkPolyDataMapper
();
mapper
.
SetInputConnection
(
transformTexture
.
GetOutputPort
());
vtkActor
actor
=
new
vtkActor
();
actor
.
SetMapper
(
mapper
);
actor
.
SetTexture
(
texture
);
// Create the renderer, render window and interactor.
vtkRenderer
ren
=
new
vtkRenderer
();
vtkRenderWindow
renWin
=
new
vtkRenderWindow
();
renWin
.
AddRenderer
(
ren
);
vtkRenderWindowInteractor
iren
=
new
vtkRenderWindowInteractor
();
iren
.
SetRenderWindow
(
renWin
);
// Visualize
ren
.
AddActor
(
actor
);
ren
.
SetBackground
(
Bgcolor
);
renWin
.
SetSize
(
300
,
300
);
renWin
.
Render
();
iren
.
Initialize
();
iren
.
Start
();
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment