// File: /workspace/github_cpp_makefile_star2_O3/Luthaf[P]zeopp/feature.cc
// Function: FEATURE::calculateVolume()
double FEATURE::calculateVolume(){
 
  long int i,j,counter=0;  
  double volume;

  XYZ max,min;
  XYZ box;
  XYZ pt;
  srand(randSeed2);
  SPHERE sph;
  vector <SPHERE> object; // a vector of spheres that define object (segemnt/feature/channel)

    // Draw the components located in each unit cell
    for(unsigned int i = 0; i < unitCells.size(); i++){
      vector<int> nodeIDs = ucNodes.at(i);
      DELTA_POS disp = unitCells.at(i);
      
      // Iterate over all nodes in the unit cell
      for(unsigned int j = 0; j < nodeIDs.size(); j++){
	DIJKSTRA_NODE curNode = nodes.at(nodeIDs.at(j));
	
	// Find node coordinates

        if(dimensionality<1) 
           { // if feature is not a channel, use reconstrcted feature
	   sph.x = curNode.x + v_a.x*disp.x + v_b.x*disp.y + v_c.x*disp.z;
	   sph.y = curNode.y + v_a.y*disp.x + v_b.y*disp.y + v_c.y*disp.z;
	   sph.z = curNode.z + v_a.z*disp.x + v_b.z*disp.y + v_c.z*disp.z;
           } else {
           sph.x = nodes.at(nodeIDs.at(j)).x;sph.y = nodes.at(nodeIDs.at(j)).y;sph.z = nodes.at(nodeIDs.at(j)).z;
//           cout << "draw sphere { " << sph.x << "  " << sph.y << "  " << sph.z << " } radius 0.1 " << "\n"; 
           };

	sph.r = SPHERE_SCALE*curNode.max_radius;

        object.push_back(sph);

        if(object.size()==1)
          { // first sphere added
          min.x=sph.x-sph.r;max.x=sph.x+sph.r;
          min.y=sph.y-sph.r;max.y=sph.y+sph.r;
          min.z=sph.z-sph.r;max.z=sph.z+sph.r;
          }else
          {
          if(min.x>(sph.x-sph.r)) min.x=sph.x-sph.r;
          if(max.x<(sph.x+sph.r)) max.x=sph.x+sph.r;
          if(min.y>(sph.y-sph.r)) min.y=sph.y-sph.r;
          if(max.y<(sph.y+sph.r)) max.y=sph.y+sph.r;
          if(min.z>(sph.z-sph.r)) min.z=sph.z-sph.r;
          if(max.z<(sph.z+sph.r)) max.z=sph.z+sph.r;
          };
		
      }
    } // end of analysis of object




  box.x=max.x-min.x;
  box.y=max.y-min.y;
  box.z=max.z-min.z;
 
  volume=box.x*box.y*box.z;

  cout << "Segment Box volume= " << volume << "\n"; 

// Now MC integration of volume

// example of random generation
// //     double theta = (rand()*1.0/RAND_MAX)*2*pi;

  for(i=0;i<N_MC_SAMPLE;i++)
     {

     pt.x = (rand()*1.0/RAND_MAX)*box.x+min.x;
     pt.y = (rand()*1.0/RAND_MAX)*box.y+min.y;
     pt.z = (rand()*1.0/RAND_MAX)*box.z+min.z;


     for(j=0;j<(int)object.size();j++)
        {
        if(calcEuclideanDistance(pt.x,pt.y,pt.z,object[j].x,object[j].y,object[j].z)<object[j].r)
           {
           counter++;
           break;
           };
        };

     };

volume=volume*((double)(N_MC_SAMPLE-counter))/(double)N_MC_SAMPLE;

return volume;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
movq %rdi, %rbx
leaq 0x60(%rsp), %rdi
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
callq 0x84364
leaq 0x20(%rsp), %rdi
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
callq 0x84364
leaq 0xd0(%rsp), %rdi
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
callq 0x84364
leaq 0xa8(%rsp), %rdi
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
callq 0x84364
movl $0x3b4ca6f5, %edi       # imm = 0x3B4CA6F5
callq 0x4410
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq 0x98(%rbx), %rax
cmpq 0x90(%rbx), %rax
je 0x7903f
leaq 0x110(%rsp), %r15
xorl %r14d, %r14d
movabsq $-0x5555555555555555, %r13 # imm = 0xAAAAAAAAAAAAAAAB
movq 0xa8(%rbx), %rax
movq 0xb0(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %r14, %rdx
jbe 0x7926f
leaq (%r14,%r14,2), %r12
leaq (%rax,%r12,8), %rsi
leaq 0x78(%rsp), %rdi
callq 0xe8f8
movq 0x90(%rbx), %rax
movq 0x98(%rbx), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
imulq %r13, %rdx
cmpq %r14, %rdx
jbe 0x7925e
movq 0x78(%rsp), %rdi
cmpq %rdi, 0x80(%rsp)
je 0x79008
movq %r14, 0xe8(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl (%rax,%r12,4), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0x4(%rax,%r12,4), %xmm1
xorps %xmm2, %xmm2
cvtsi2sdl 0x8(%rax,%r12,4), %xmm2
movapd %xmm2, 0x170(%rsp)
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
movapd %xmm2, 0x160(%rsp)
movapd %xmm1, 0xc0(%rsp)
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
movapd %xmm1, 0x150(%rsp)
movapd %xmm0, 0x90(%rsp)
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
movapd %xmm0, 0x140(%rsp)
movl $0x1, %ebp
xorl %r12d, %r12d
movslq (%rdi,%r12,4), %rsi
movq 0x60(%rbx), %r14
movq 0x68(%rbx), %rdx
subq %r14, %rdx
sarq $0x3, %rdx
movabsq $-0x71c71c71c71c71c7, %rax # imm = 0x8E38E38E38E38E39
imulq %rax, %rdx
cmpq %rsi, %rdx
jbe 0x79250
leaq (%rsi,%rsi,8), %r13
leaq (%r14,%r13,8), %rsi
addq $0x20, %rsi
movupd -0x20(%rsi), %xmm0
movupd -0x10(%rsi), %xmm1
movapd %xmm1, 0x100(%rsp)
movapd %xmm0, 0xf0(%rsp)
movq %r15, %rdi
callq 0x37e9e
leaq (%r14,%r13,8), %rax
movb 0x40(%rax), %cl
movb %cl, 0x20(%r15)
movq 0x38(%rax), %rax
movq %rax, 0x18(%r15)
cmpl $0x0, 0x108(%rbx)
jle 0x78ddb
movq 0x78(%rsp), %rax
movq 0x80(%rsp), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %r12, %rdx
jbe 0x7923f
movslq (%rax,%r12,4), %r12
movq 0x60(%rbx), %rax
movq 0x68(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x71c71c71c71c71c7, %rcx # imm = 0x8E38E38E38E38E39
imulq %rcx, %rdx
cmpq %r12, %rdx
jbe 0x7923f
leaq (%r12,%r12,8), %rcx
movups 0x8(%rax,%rcx,8), %xmm0
movaps %xmm0, 0x40(%rsp)
movsd 0x18(%rax,%rcx,8), %xmm0
jmp 0x78e6d
movupd 0xf8(%rsp), %xmm0
movupd 0xc0(%rbx), %xmm1
mulpd 0x140(%rsp), %xmm1
addpd %xmm0, %xmm1
movupd 0xd8(%rbx), %xmm0
mulpd 0x150(%rsp), %xmm0
addpd %xmm1, %xmm0
movupd 0xf0(%rbx), %xmm1
mulpd 0x160(%rsp), %xmm1
addpd %xmm0, %xmm1
movapd %xmm1, 0x40(%rsp)
movsd 0xd0(%rbx), %xmm0
mulsd 0x90(%rsp), %xmm0
addsd 0x108(%rsp), %xmm0
movsd 0xe8(%rbx), %xmm1
mulsd 0xc0(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd 0x100(%rbx), %xmm0
mulsd 0x170(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x128(%rsp), %xmm0
mulsd 0xd934c(%rip), %xmm0    # 0x1521d0
movsd %xmm0, 0x58(%rsp)
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x78eb6
movapd 0x40(%rsp), %xmm0
movapd 0x50(%rsp), %xmm1
movupd %xmm1, 0x10(%rsi)
movupd %xmm0, (%rsi)
addq $0x20, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x78ec8
movq %rsp, %rdi
leaq 0x40(%rsp), %rdx
callq 0x499ba
movq 0x8(%rsp), %rsi
subq (%rsp), %rsi
cmpq $0x20, %rsi
jne 0x78f1b
movsd 0x58(%rsp), %xmm0
movapd 0x40(%rsp), %xmm1
movapd %xmm0, %xmm2
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
movapd %xmm1, %xmm3
subpd %xmm2, %xmm3
movapd %xmm3, 0x20(%rsp)
addpd %xmm1, %xmm2
movapd %xmm2, 0x60(%rsp)
movsd 0x50(%rsp), %xmm1
movapd %xmm1, %xmm2
subsd %xmm0, %xmm2
movsd %xmm2, 0x30(%rsp)
addsd %xmm1, %xmm0
jmp 0x78fb1
movsd 0x20(%rsp), %xmm3
movsd 0x40(%rsp), %xmm1
movsd 0x58(%rsp), %xmm0
movapd %xmm1, %xmm2
subsd %xmm0, %xmm2
ucomisd %xmm2, %xmm3
jbe 0x78f41
movsd %xmm2, 0x20(%rsp)
addsd %xmm0, %xmm1
ucomisd 0x60(%rsp), %xmm1
jbe 0x78f53
movsd %xmm1, 0x60(%rsp)
movsd 0x28(%rsp), %xmm3
movsd 0x48(%rsp), %xmm1
movapd %xmm1, %xmm2
subsd %xmm0, %xmm2
ucomisd %xmm2, %xmm3
jbe 0x78f73
movsd %xmm2, 0x28(%rsp)
addsd %xmm0, %xmm1
ucomisd 0x68(%rsp), %xmm1
jbe 0x78f85
movsd %xmm1, 0x68(%rsp)
movsd 0x30(%rsp), %xmm3
movsd 0x50(%rsp), %xmm1
movapd %xmm1, %xmm2
subsd %xmm0, %xmm2
ucomisd %xmm2, %xmm3
jbe 0x78fa5
movsd %xmm2, 0x30(%rsp)
addsd %xmm1, %xmm0
ucomisd 0x70(%rsp), %xmm0
jbe 0x78fb7
movsd %xmm0, 0x70(%rsp)
movq 0x110(%rsp), %rdi
testq %rdi, %rdi
je 0x78fd4
movq 0x120(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movl %ebp, %r12d
movq 0x78(%rsp), %rdi
movq 0x80(%rsp), %rax
subq %rdi, %rax
sarq $0x2, %rax
incl %ebp
cmpq %r12, %rax
ja 0x78d05
movq 0xe8(%rsp), %r14
movabsq $-0x5555555555555555, %r13 # imm = 0xAAAAAAAAAAAAAAAB
testq %rdi, %rdi
je 0x7901d
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x98(%rbx), %rax
subq 0x90(%rbx), %rax
incl %r14d
sarq $0x2, %rax
imulq %r13, %rax
cmpq %r14, %rax
ja 0x78c2d
movapd 0x60(%rsp), %xmm0
subpd 0x20(%rsp), %xmm0
movapd %xmm0, 0x90(%rsp)
movapd %xmm0, 0xd0(%rsp)
movsd 0x70(%rsp), %xmm0
subsd 0x30(%rsp), %xmm0
movsd %xmm0, 0xc0(%rsp)
movsd %xmm0, 0xe0(%rsp)
movq 0x11bf3e(%rip), %rdi    # 0x194fc0
leaq 0xdbea1(%rip), %rsi     # 0x154f2a
movl $0x14, %edx
callq 0x44e0
movapd 0x90(%rsp), %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
mulsd %xmm1, %xmm0
mulsd 0xc0(%rsp), %xmm0
movq 0x11bf08(%rip), %rdi    # 0x194fc0
movapd %xmm0, 0x90(%rsp)
callq 0x46b0
leaq 0xda551(%rip), %rsi     # 0x15361e
movl $0x1, %edx
movq %rax, %rdi
callq 0x44e0
xorl %r14d, %r14d
xorl %ebx, %ebx
callq 0x4150
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0xd84fd(%rip), %xmm1    # 0x1515f0
divsd %xmm1, %xmm0
mulsd 0xd0(%rsp), %xmm0
addsd 0x20(%rsp), %xmm0
movsd %xmm0, 0xa8(%rsp)
callq 0x4150
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd 0xd84cd(%rip), %xmm0    # 0x1515f0
mulsd 0xd8(%rsp), %xmm0
addsd 0x28(%rsp), %xmm0
movsd %xmm0, 0xb0(%rsp)
callq 0x4150
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd 0xd84a1(%rip), %xmm0    # 0x1515f0
mulsd 0xe0(%rsp), %xmm0
addsd 0x30(%rsp), %xmm0
movsd %xmm0, 0xb8(%rsp)
movq (%rsp), %rdi
movq 0x8(%rsp), %rax
subq %rdi, %rax
shlq $0x1b, %rax
testq %rax, %rax
jle 0x791e6
xorl %r15d, %r15d
xorl %r12d, %r12d
movsd 0xa8(%rsp), %xmm0
movsd 0xb0(%rsp), %xmm1
movsd 0xb8(%rsp), %xmm2
movsd (%rdi,%r15), %xmm3
movsd 0x8(%rdi,%r15), %xmm4
movsd 0x10(%rdi,%r15), %xmm5
callq 0x84cbb
movq (%rsp), %rdi
movsd 0x18(%rdi,%r15), %xmm1
ucomisd %xmm0, %xmm1
ja 0x791e3
incq %r12
movq 0x8(%rsp), %rax
subq %rdi, %rax
shrq $0x5, %rax
cltq
addq $0x20, %r15
cmpq %rax, %r12
jl 0x79182
jmp 0x791e6
incq %rbx
incq %r14
cmpq $0x186a0, %r14          # imm = 0x186A0
jne 0x790df
testq %rdi, %rdi
je 0x79208
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movl $0x186a0, %eax          # imm = 0x186A0
subq %rbx, %rax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
movapd 0x90(%rsp), %xmm0
mulsd %xmm1, %xmm0
divsd 0xdba4b(%rip), %xmm0    # 0x154c78
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd44af(%rip), %rdi     # 0x14d6f5
movq %r12, %rsi
xorl %eax, %eax
callq 0x4630
leaq 0xd449e(%rip), %rdi     # 0x14d6f5
xorl %eax, %eax
callq 0x4630
leaq 0xd4490(%rip), %rdi     # 0x14d6f5
movq %r14, %rsi
xorl %eax, %eax
callq 0x4630
leaq 0xd447f(%rip), %rdi     # 0x14d6f5
movq %r14, %rsi
xorl %eax, %eax
callq 0x4630
jmp 0x7928a
jmp 0x7928a
jmp 0x7928a
jmp 0x79291
jmp 0x79296
movq %rax, %rbx
jmp 0x792d0
jmp 0x79291
movq %rax, %rbx
jmp 0x792b6
movq %rax, %rbx
movq 0x110(%rsp), %rdi
testq %rdi, %rdi
je 0x792b6
movq 0x120(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x792d0
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x792e6
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq %rbx, %rdi
callq 0x4780