Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dolfin_warp
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Genet
dolfin_warp
Commits
923a1e79
Commit
923a1e79
authored
6 years ago
by
Martin Genet
Browse files
Options
Downloads
Patches
Plain Diff
First test of dealing with generated images
parent
8e6f3f78
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
__init__.py
+1
-0
1 addition, 0 deletions
__init__.py
generated_image_expressions_cpp.py
+91
-0
91 additions, 0 deletions
generated_image_expressions_cpp.py
with
92 additions
and
0 deletions
__init__.py
+
1
−
0
View file @
923a1e79
...
@@ -13,6 +13,7 @@ from compute_strains import *
...
@@ -13,6 +13,7 @@ from compute_strains import *
from
compute_displacements
import
*
from
compute_displacements
import
*
from
compute_displacement_error
import
*
from
compute_displacement_error
import
*
from
compute_quadrature_degree
import
*
from
compute_quadrature_degree
import
*
from
generated_image_expressions_cpp
import
*
from
image_expressions_cpp
import
*
from
image_expressions_cpp
import
*
from
plot_strains
import
*
from
plot_strains
import
*
from
plot_displacement_error
import
*
from
plot_displacement_error
import
*
...
...
This diff is collapsed.
Click to expand it.
generated_image_expressions_cpp.py
0 → 100644
+
91
−
0
View file @
923a1e79
#coding=utf8
################################################################################
### ###
### Created by Martin Genet, 2016-2018 ###
### ###
### École Polytechnique, Palaiseau, France ###
### ###
################################################################################
################################################################################
def
get_ExprGenIm_cpp
(
im_dim
,
verbose
=
0
):
assert
(
im_dim
in
(
2
,
3
))
ExprGenIm_cpp
=
'''
\
#include <string.h>
#include <vtkSmartPointer.h>
#include <vtkStructuredPointsReader.h>
#include <vtkXMLImageDataReader.h>
#include <vtkImageData.h>
#include <vtkImageInterpolator.h>
double getStaticScalingFactor(const char* scalar_type_as_string)
{
if (strcmp(scalar_type_as_string,
"
unsigned char
"
) == 0) return pow(2, 8)-1;
if (strcmp(scalar_type_as_string,
"
unsigned short
"
) == 0) return pow(2, 16)-1;
if (strcmp(scalar_type_as_string,
"
unsigned int
"
) == 0) return pow(2, 32)-1;
if (strcmp(scalar_type_as_string,
"
unsigned long
"
) == 0) return pow(2, 64)-1;
if (strcmp(scalar_type_as_string,
"
float
"
) == 0) return 1.;
if (strcmp(scalar_type_as_string,
"
double
"
) == 0) return 1.;
assert (0);
}
namespace dolfin
{
class MyExpr : public Expression
{
vtkSmartPointer<vtkImageInterpolator> interpolator;
double static_scaling;
public:
MyExpr():
Expression()
{
}
void init_image(
const char* filename)
{
vtkSmartPointer<vtkXMLImageDataReader> reader = vtkSmartPointer<vtkXMLImageDataReader>::New();
reader->SetFileName(filename);
reader->Update();
static_scaling = getStaticScalingFactor(reader->GetOutput()->GetScalarTypeAsString());
interpolator = vtkSmartPointer<vtkImageInterpolator>::New();
interpolator->SetInterpolationModeToLinear();
interpolator->SetOutValue(0.);
interpolator->Initialize(reader->GetOutput());
interpolator->Update();
}
void eval(Array<double>& expr, const Array<double>& X) const
{
'''
+
(
'''
std::cout <<
"
X =
"
<< X.str(1) << std::endl;
'''
)
*
(
verbose
)
+
(
'''
X3D[0] = X[0];
X3D[1] = X[1];
'''
+
(
'''
std::cout <<
"
X3D =
"
<< X3D.str(1) << std::endl;
'''
)
*
(
verbose
)
+
'''
interpolator->Interpolate(X3D.data(), expr.data());
'''
)
*
(
im_dim
==
2
)
+
(
'''
interpolator->Interpolate(X.data(), expr.data());
'''
)
*
(
im_dim
==
3
)
+
(
'''
std::cout <<
"
expr =
"
<< expr.str(1) << std::endl;
'''
)
*
(
verbose
)
+
'''
expr[0] /= static_scaling;
'''
+
(
'''
std::cout <<
"
expr =
"
<< expr.str(1) << std::endl;
'''
)
*
(
verbose
)
+
'''
}
};
}
'''
#print ExprGenIm_cpp
return
ExprGenIm_cpp
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