function []=writeply(densePC,name)
%% write final Pcloud with texture
% mnm=size(densePC);
% %im1of_res=imresize(im1of,[mnm(1) mnm(2)]);
 plyPoint = [];
 plyColor = [];
% X=[];
% [x,y]=meshgrid(1:mnm(2),mnm(1):-1:1);
X=densePC;
colorR = 255*X(3,:)/max(X(3,:));
colorG = colorR;
colorB = colorR;
%     colorR = reshape(im1of_res(:,:,1)',[1 mnm(1)*mnm(2)]);
%     if size(im1orig,3)>1
%         colorG = reshape(im1of_res(:,:,2)',[1 mnm(1)*mnm(2)]);
%         colorB = reshape(im1of_res(:,:,3)',[1 mnm(1)*mnm(2)]);
%     else
%         colorG = reshape(im1of_res(:,:,1)',[1 mnm(1)*mnm(2)]);
%         colorB = reshape(im1of_res(:,:,1)',[1 mnm(1)*mnm(2)]);
%     end
%   %  X(1,:)=X(1,:)*100;
%   %  X(2,:)=X(2,:)*100;
plyPoint = [plyPoint X(1:3,:)];
plyColor = [plyColor [colorR; colorG; colorB]];


points2ply(name,plyPoint,plyColor);