source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/LaserDataCollection/generate_vrml_faceset_triangle.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 6.3 KB
Line 
1% *  This code was used in the following articles:
2% *  [1] Learning 3-D Scene Structure from a Single Still Image,
3% *      Ashutosh Saxena, Min Sun, Andrew Y. Ng,
4% *      In ICCV workshop on 3D Representation for Recognition (3dRR-07), 2007.
5% *      (best paper)
6% *  [2] 3-D Reconstruction from Sparse Views using Monocular Vision,
7% *      Ashutosh Saxena, Min Sun, Andrew Y. Ng,
8% *      In ICCV workshop on Virtual Representations and Modeling
9% *      of Large-scale environments (VRML), 2007.
10% *  [3] 3-D Depth Reconstruction from a Single Still Image,
11% *      Ashutosh Saxena, Sung H. Chung, Andrew Y. Ng.
12% *      International Journal of Computer Vision (IJCV), Aug 2007.
13% *  [6] Learning Depth from Single Monocular Images,
14% *      Ashutosh Saxena, Sung H. Chung, Andrew Y. Ng.
15% *      In Neural Information Processing Systems (NIPS) 18, 2005.
16% *
17% *  These articles are available at:
18% *  http://make3d.stanford.edu/publications
19% *
20% *  We request that you cite the papers [1], [3] and [6] in any of
21% *  your reports that uses this code.
22% *  Further, if you use the code in image3dstiching/ (multiple image version),
23% *  then please cite [2].
24% * 
25% *  If you use the code in third_party/, then PLEASE CITE and follow the
26% *  LICENSE OF THE CORRESPONDING THIRD PARTY CODE.
27% *
28% *  Finally, this code is for non-commercial use only.  For further
29% *  information and to obtain a copy of the license, see
30% *
31% *  http://make3d.stanford.edu/publications/code
32% *
33% *  Also, the software distributed under the License is distributed on an
34% * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
35% *  express or implied.   See the License for the specific language governing
36% *  permissions and limitations under the License.
37% *
38% */
39function [] = generate_vrml_faceset_triangle(vrmlDirectory, vrmlFilename, imgDirectory, imageFilename, leftTriangle, rightTriangle)
40% this function play with the VRML
41% using only FaceSet
42
43% if nargin < 6
44%     a = 0.70783777 %0.129; % horizontal physical size of image plane normalized to focal length (in meter)
45%     b = 0.946584169%0.085; % vertical physical size of image plane normalized to focal length (in meter)
46%     Ox = -0.010727086; % camera origin offset from the image center in horizontal direction
47%     Oy = -0.0111130176; % camera origin offset from the image center in vertical direction
48% elseif nargin < 7
49%     b = a;
50%     Ox = -0.010727086; % camera origin offset from the image center in horizontal direction
51%     Oy = -0.0111130176; % camera origin offset from the image center in vertical direction
52% end
53%
54% % define global variable
55% global GeneralDataFolder ScratchDataFolder LocalFolder;
56%
57% vrml_filename = ['test_faceset_triangle' filename '_' DepthDirectory '.wrl'];
58% LowResImgIndexSuperpixelSepTemp = LowResImgIndexSuperpixelSep;
59imgDirectoryMod=strcat('.',imgDirectory);
60A = imread([imgDirectoryMod imageFilename]);
61
62% [VertYSize HoriXSize] = size(A);
63% nu_patch = VertYSize* HoriXSize;
64% PlaneParameterTureTemp = PlaneParameterTure;
65
66% calculate ray
67% ray = GenerateRay(HoriXSize,VertYSize,'center'); %[ horiXSizeLowREs VertYSizeLowREs 3]
68
69% calculate Position3D
70% DepthTureProj = 1./sum(permute(reshape(PlaneParameterTureTemp(1:3,LowResImgIndexSuperpixelSepTemp),3,VertYSize,[]),[2 3 1]).*ray,3);
71% Position3D = im_cr2w_cr(DepthTureProj,ray);
72
73% calculate Position3DCoord
74Position3DCoord = [];
75for i = 1:min(size(leftTriangle,1),size(rightTriangle,1))
76    Position3DCoord = [Position3DCoord assignTriangleValues(leftTriangle(i,3,3:5))' assignTriangleValues(leftTriangle(i,1,3:5))' assignTriangleValues(leftTriangle(i,2,3:5))' ...
77        assignTriangleValues(rightTriangle(i,2,3:5))' assignTriangleValues(rightTriangle(i,1,3:5))' assignTriangleValues(rightTriangle(i,3,3:5))'];
78end
79
80%     for j = 1:HoriXSize-1
81%         Position3DCoord = [Position3DCoord Position3D(:,i,j) Position3D(:,i+1,j) Position3D(:,i+1,j+1) Position3D(:,i,j) Position3D(:,i+1,j+1) Position3D(:,i,j+1)];
82%     end
83% end   
84Position3DCoord(3,:) = -Position3DCoord(3,:); % important to make z direction negative
85
86% calculate PositionTexCoord
87% PositionTex = permute(ray(:,:,1:2)./repmat(cat(3,a,b),[VertYSize HoriXSize 1])+0.5,[3 1 2]);
88PositionTexCoord = [];
89for i = 1:min(size(leftTriangle,1),size(rightTriangle,1))
90    PositionTexCoord = [PositionTexCoord assignTriangleValues(leftTriangle(i,3,1:2))' assignTriangleValues(leftTriangle(i,1,1:2))' assignTriangleValues(leftTriangle(i,2,1:2))' ...
91        assignTriangleValues(rightTriangle(i,2,1:2))' assignTriangleValues(rightTriangle(i,1,1:2))' assignTriangleValues(rightTriangle(i,3,1:2))'];
92end
93% PositionTexCoord = PositionTexCoord./([2272 1704]');
94PositionTexCoord = PositionTexCoord./(repmat([2272 1704]',1,length(PositionTexCoord)));
95pathName = pwd;
96imageForVRMLfile=strcat(pathName,imgDirectory,imageFilename);
97
98    % inital header
99disp('writing vrml..');
100fp = fopen([vrmlDirectory vrmlFilename],'w');
101
102fprintf(fp, '#VRML V2.0 utf8\n');
103
104% add navigate_info
105fprintf(fp, 'NavigationInfo {\n');
106fprintf(fp, '  headlight TRUE\n');
107fprintf(fp, '  type ["FLY", "ANY"]}\n\n');
108
109% add viewpoint
110fprintf(fp, 'Viewpoint {\n');
111fprintf(fp, '    position        0 0.0 0.0\n');
112fprintf(fp, '    orientation     0 0 0 0\n');
113fprintf(fp, '    fieldOfView     0.1\n');
114fprintf(fp, '    description "Original"}\n');
115
116% add Shape for texture faceset
117fprintf(fp, 'Shape{\n');
118fprintf(fp, '  appearance Appearance {\n');
119fprintf(fp, ['   texture ImageTexture { url "' imageForVRMLfile '" }\n']);
120fprintf(fp, '  }\n');
121fprintf(fp, '  geometry IndexedFaceSet {\n');
122fprintf(fp, '    coord Coordinate {\n');
123
124% insert coordinate in 3d
125% =======================
126fprintf(fp, '      point [ \n');
127fprintf(fp, '        %f %f %f,\n',Position3DCoord);
128fprintf(fp, '      ]\n');
129fprintf(fp, '    }\n');
130
131% insert coordinate index in 3d
132fprintf(fp, '    coordIndex [\n');
133Position3DCoordOrdeerIndex = 0:(size(Position3DCoord,2)-1);
134fprintf(fp, '              %g %g %g -1,\n',Position3DCoordOrdeerIndex);
135fprintf(fp, '    ]\n');
136
137% insert texture coordinate
138fprintf(fp, '    texCoord TextureCoordinate {\n');
139fprintf(fp, '      point [\n');
140fprintf(fp, '              %g %g,\n',PositionTexCoord);
141fprintf(fp, '        ]\n');
142fprintf(fp, '    }\n');
143% ==================================
144fprintf(fp, '  }\n');
145fprintf(fp, '}\n');
146
147% close the file
148fclose(fp);
149disp('done :)');
Note: See TracBrowser for help on using the repository browser.