# Mesh based on breast image using P2 finite elements

**URL:** https://community.freefem.org/t/mesh-based-on-breast-image-using-p2-finite-elements/3862
**Category:** General Discussion
**Created:** [April 14, 2025, 3:36pm UTC](https://community.freefem.org/t/mesh-based-on-breast-image-using-p2-finite-elements/3862 "2025-04-14T15:36:42Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![lassounon](https://avatars.discourse-cdn.com/v4/letter/l/bbe5ce/32.png) [@lassounon](https://community.freefem.org/u/lassounon)
#### Post date: [April 14, 2025, 3:36pm UTC](https://community.freefem.org/t/mesh-based-on-breast-image-using-p2-finite-elements/3862/1 "2025-04-14T15:36:42Z")

</div>

Hello everyone.  
I used the image-based mesh generation code (Lemanlake example in the Freefem documentation, p. 194) to generate a breast mesh using P1 finite elements. I want the same thing with P2 finite elements. However, FreeFem has stopped working if I replace P1 with P2. Please help me fix what’s wrong with P2.

Thank you very much for your help.

[BreastMesh-P2.zip](https://community.freefem.org/uploads/short-url/uKc2OswJBhfdmr0emmzdNmQvRzR.zip) (87.9 KB)

string legende;  
int m=10;  
load “ppm2rnm”  
load “isoline”  
real L=3;  
string sein = “breast05.pgm”;  
real AreaLac = 500.03;  
real hsize =0.2;  
real[int, int] Curves(3, 2);  
int[int] be(1);  
int nc;  
{  
real[int, int] ff1(sein);  
int nx = ff1.n, ny = ff1.m;  
mesh Th = square(nx-1, ny-1, [(nx-1)_(x)/(20_L), (ny-1)_(1-y)/(20_L)]);  
fespace Vh(Th, P2); ////////////////////////////////////////// (I changed P1 to P2)/////////////////////////////  
Vh f1;  
f1 = ff1;  
nc = isoline(Th, f1, iso=0.25, close=1, Curves, beginend=be, smoothing=.1, ratio=0.25);  
}  
int ic0 = be(0), ic1 = be(1)-1;  
int NC = Curves(2, ic1)/hsize;  
border G(t=0, 1){P=Curve(Curves, ic0, ic1, t);}  
mesh Th=buildmesh(G(NC));  
plot(Th);

The mesh with P1 is below. What if I want the same mesh with P2 finite elements ?

 ![breast-P1Mesh](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/8/8d3710ab349d199658d9c883d8b688989c09f61a.png)

---

<div class="post-metadata">

### Author: ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)
#### Post date: [April 18, 2025, 8:53am UTC](https://community.freefem.org/t/mesh-based-on-breast-image-using-p2-finite-elements/3862/2 "2025-04-18T08:53:59Z")

</div>

Hello,  
You have a mesh. Thus you can define P1 or P2 elements on this mesh. I don’t see really what is your problem, it depends what you want to do with this mesh.

---

<div class="post-metadata">

### Author: ![lassounon](https://avatars.discourse-cdn.com/v4/letter/l/bbe5ce/32.png) [@lassounon](https://community.freefem.org/u/lassounon)
#### Post date: [April 18, 2025, 10:55am UTC](https://community.freefem.org/t/mesh-based-on-breast-image-using-p2-finite-elements/3862/3 "2025-04-18T10:55:18Z")

</div>

Hello,  
Thank you very much for your response. Since the mesh is defined using P1, I would like to know if it is possible to use P2 instead. To ensure consistency with the mesh, I attempted to redefine it as P2 by replacing P1 with P2 in Th, but that approach did not work, I understand. I appreciate the clarity of your response. Thank you again.

---

<div class="post-metadata">

### Author: ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)
#### Post date: [April 18, 2025, 11:03am UTC](https://community.freefem.org/t/mesh-based-on-breast-image-using-p2-finite-elements/3862/4 "2025-04-18T11:03:00Z")

</div>

The space P1 is used to build the mesh. But once you have the mesh, you can use P2 elements (or any other elements) on this mesh if you like.
