alecjacobson / gptoolbox

Matlab toolbox for Geometry Processing.
MIT License
628 stars 166 forks source link

Points projection on an object #48

Closed FeazAlkadi closed 6 years ago

FeazAlkadi commented 6 years ago

Hello Alec,

I was just wondering if you have made a function that works like the function (projpartIGES) from igestoolbox by Per Bergström
https://www.mathworks.com/matlabcentral/fileexchange/13253-iges-toolbox

As shown in the attached pictures,this function creates grid points in 2D (green color)and project them onto the surface of an object in IGS file format,and return points in 3D (Red color) with dimensions according to the object surface.

For my application: I'm looking for a function that does exactly the same thing BUT for a body made of triangle mesh (V and F). And has the ability to make two different grid spacing one for Primary direction (dp) and the other for Secondary direction (ds).

Here I'm also attaching the code for the example with small modifications: I'm not sure if you need to compile makeIGESmex for this example.

As usual, Thank you so much for the great help.

% exampleProjection.m plots an IGES CAD-object and project points on its surface

% Compile the c-files (if necessary)
 %makeIGESmex;
%%
% Load parameter data from IGES-file.
[ParameterData,EntityType,numEntityType,unknownEntityType,numunknownEntityType]=iges2matlab('IGESfiles/example.igs');

% Project a set of points in a regular grid on the surface

% Projection data

R=[2000;0;600]; % Grid origin
normal=[0;0;-1]; % Direction of projection
normal=normal/norm(normal);
% pdir=randn(3,1); % First (primary) direction of grid
% pdir=pdir-dot(pdir,normal)*normal;
% pdir=pdir/norm(pdir);
% sdir=cross(pdir,normal); % Second (secondary) direction of grid
% sdir=sdir/norm(sdir);
        pdir=[0;1;0];%pdir/norm(pdir);
        %pdir=pdir-dot(pdir,normal)*normal;
        sdir=cross(-pdir,normal); % Second (secondary) direction of grid
dp=80; % Grid spacing
nppos=60; % Number of positive grids in primary direction
npneg=80; % Number of negative grids in primary direction
nspos=65; % Number of positive grids in secondary direction
nsneg=75; % Number of negative grids in secondary direction

% Do the projection
[model,UV,srfind,srfDerivind,srfDer,numpoints]=projpartIGES(ParameterData,R,normal,pdir,sdir,dp,nppos,npneg,nspos,nsneg);

% Plots

% Plot the IGES object
figno=1;
plotIGES(ParameterData,1,figno,[],0);

Pnts=zeros(3,(npneg+1+nppos)*(nsneg+1+nspos));

ind=0;
for i=-npneg:nppos
    for j=-nsneg:nspos
        ind=ind+1;
        Pnts(:,ind)=R+i*dp*pdir+j*dp*sdir;
    end
end

plot3(Pnts(1,:),Pnts(2,:),Pnts(3,:),'.','Color',[0.1 0.5 0.4]);

% Plot normal, starting at grid origin
lines=[R R+15*dp*normal];
plot3(lines(1,:),lines(2,:),lines(3,:),'r-');

% Plot pdir, starting at grid origin
lines=[R R+15*dp*pdir];
plot3(lines(1,:),lines(2,:),lines(3,:),'g-');

% Plot sdir, starting at grid origin
lines=[R R+15*dp*sdir];
plot3(lines(1,:),lines(2,:),lines(3,:),'b-');

% Plot projected points
plot3(model(1,srfind>0),model(2,srfind>0),model(3,srfind>0),'.','Color','r');

axis auto

hold off;

Top View

top view

3D View

3d view

alecjacobson commented 6 years ago

You can do this in a slow way using ray_mesh_intersect

To do this quickly, I'd use libigl's ray_mesh_intersect instead. You could have a look at mex/ambient_occlusion.cpp for clues on how to do that.

FeazAlkadi commented 6 years ago

Sounds good.

I tried to compile ambient_occlusion.cpp but I'm having a problem with that

clearvars

clc
path_to_eigen='C:\Users\faa23\Desktop\3D_DiskTop\MatlabCodes\iges (original)\eigen-eigen-';
% Check if the eigen path is correct
assert(exist([path_to_eigen '\Eigen\Core'],'file')==2)

path_to_libigl='C:\Users\faa23\Desktop\3D_DiskTop\MatlabCodes\iges (original)\libigl';
 %Check if the libig path is correct
assert(exist([path_to_libigl '\include\igl\embree\EmbreeIntersector.h'],'file')==2)
%%

MEXOPTS={'-v','-largeArrayDims','-DMEX'};

EIGEN_INC= ['-I' path_to_eigen];

LIBIGL_INC=['-I' path_to_libigl '\include'];
LIBIGL_FLAGS='-DIGL_SKIP';
LIBIGL_LIB={'-DIGL_SKIP'};
LIBIGL_LIBMATLAB='-DIGL_SKIP';
LIBIGL_LIBCGAL='-DIGL_SKIP';
LIBIGL_LIBCORK='-DIGL_NO_CORK';
LIBIGL_BASE={LIBIGL_INC, LIBIGL_FLAGS,LIBIGL_LIB{:}, LIBIGL_LIBMATLAB};

mex( ...
  MEXOPTS{:}, ...
  LIBIGL_BASE{:},EIGEN_INC, ...
  'ambient_occlusion.cpp');

I always get this error:

Error using mex ambient_occlusion.cpp c:\users\faa23\desktop\3d_disktop\matlabcodes\iges (original)\libigl\include\igl\EPS.h(16): warning C4305: 'initializing': truncation from 'double' to 'float' c:\users\faa23\desktop\3d_disktop\matlabcodes\iges (original)\libigl\include\igl\EPS.h(17): warning C4305: 'initializing': truncation from 'double' to 'float' c:\users\faa23\desktop\3d_disktop\matlabcodes\iges (original)\libigl\include\igl\embree\EmbreeIntersector.h(24): fatal error C1083: Cannot open include file: 'embree2/rtcore.h': No such file or directory

Error in STLoffset (line 25) mex( ...

The thing is I couldnot find embree2 in libigl at all !!! Do you have any suggestion ? Thanks a lot

FeazAlkadi commented 6 years ago

I only have libigl/external/embree in the file i downloaded. embree is empty folder I think you are right, I didn't clone all the submodules !!

Where can i find the instructions, please?

alecjacobson commented 6 years ago

it's a subdirectory. Please read this entire line:

libigl/external/embree/include/embree2/rtcore.h

alecjacobson commented 6 years ago

try

git submodule update --init

in your libigl folder

FeazAlkadi commented 6 years ago

yes, this is what i mean libigl/external/embree
is empty, Nothing in it.

and sorry for that, But i'm not an expert with Matlab, so I don't know what do you mean by :

try

git submodule update --init

in your libigl folder

I mean how can I do that in the command window or in a script?

FeazAlkadi commented 6 years ago

I think i should close this issue since there is another open issue for compiling ambient_occlusion.cpp with windows 7.

Thanks Alec.