Skip to content

Commit 0ff7e9d

Browse files
committedMar 16, 2015
add PassArray
1 parent 72343b3 commit 0ff7e9d

File tree

9 files changed

+6456
-95493
lines changed

9 files changed

+6456
-95493
lines changed
 

‎test/LoadProcRender1/build.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
# source emsdk_set_env.sh
33

44
#my local path
5-
em++ --bind -I /Users/maurizio/Desktop/Universita/F3D/vcg-code/vcglib/ refine.cpp -s EXPORTED_FUNCTIONS="['_allocator','_refine']" -o refine.js
6-
#em++ -I ../../../vcglib/ refine.cpp -s EXPORTED_FUNCTIONS="['_allocator','_refine']" -o refine.js
5+
em++ --bind -I /Users/maurizio/Desktop/Universita/F3D/vcg-code/vcglib/ refine.cpp -s EXPORTED_FUNCTIONS="['_getLength','_getVector']" -o refine.js
6+
#em++ -I ../../../vcglib/ refine.cpp -s EXPORTED_FUNCTIONS="['_allocator','_refine']" -o refine.js
7+
# em++ refine.cpp --bind -o refine.js

‎test/LoadProcRender1/index.html

+7-6
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
//text = text.replace(/</g, "&lt;");
4242
//text = text.replace(/>/g, "&gt;");
4343
//text = text.replace('\n', '<br>', 'g');
44-
console.log(text);
44+
// console.log(text);
4545
if (element) {
4646
element.value += text + "\n";
4747
element.scrollTop = element.scrollHeight; // focus on bottom
@@ -54,14 +54,15 @@
5454
<script type="text/javascript" src="refine.js"></script>
5555

5656
<script type="text/javascript">
57-
var result = Module.ccall('refine',
57+
var result = Module.ccall('getVector',
5858
'number', // return type
5959
['number'], // argument types
6060
[1]);
61-
console.log(result);
62-
console.log(Module.getValue(result,'*'));
63-
console.log(Module.getValue(result+parseInt(4),'*'));
64-
console.log(Module.getValue(result+parseInt(8),'*'));
61+
var length = Module.ccall('getLength','number');
62+
console.log("pointer "+result);
63+
console.log("length vector "+length);
64+
for(var i=0; i<length; i++)
65+
console.log(Module.getValue(result+parseInt(i*4),'*'));
6566

6667
</script>
6768
</body>

‎test/LoadProcRender1/refine.cpp

+77-68
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,92 @@
1-
/****************************************************************************
2-
* VCGLib o o *
3-
* Visual and Computer Graphics Library o o *
4-
* _ O _ *
5-
* Copyright(C) 2004-2012 \/)\/ *
6-
* Visual Computing Lab /\/| *
7-
* ISTI - Italian National Research Council | *
8-
* \ *
9-
* All rights reserved. *
10-
* *
11-
* This program is free software; you can redistribute it and/or modify *
12-
* it under the terms of the GNU General Public License as published by *
13-
* the Free Software Foundation; either version 2 of the License, or *
14-
* (at your option) any later version. *
15-
* *
16-
* This program is distributed in the hope that it will be useful, *
17-
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
18-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19-
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
20-
* for more details. *
21-
* *
22-
****************************************************************************/
1+
// #include <stdlib.h>
2+
// #include <vector>
3+
// #include <emscripten.h>
4+
// #include <emscripten/bind.h>
5+
// #include <vcg/complex/complex.h>
6+
// #include <wrap/io_trimesh/import_off.h>
7+
// #include <wrap/io_trimesh/export_off.h>
8+
9+
// #include <vcg/complex/algorithms/refine.h>
10+
// using namespace vcg;
11+
// using namespace std;
12+
// using namespace emscripten;
13+
14+
15+
// class MyEdge;
16+
// class MyFace;
17+
// class MyVertex;
18+
// struct MyUsedTypes : public vcg::UsedTypes< vcg::Use<MyVertex> ::AsVertexType,
19+
// vcg::Use<MyEdge> ::AsEdgeType,
20+
// vcg::Use<MyFace> ::AsFaceType>{};
21+
22+
// class MyVertex : public vcg::Vertex<MyUsedTypes, vcg::vertex::Coord3f, vcg::vertex::Normal3f, vcg::vertex::Color4b, vcg::vertex::Qualityf, vcg::vertex::BitFlags >{};
23+
// class MyFace : public vcg::Face< MyUsedTypes, vcg::face::Normal3f, vcg::face::VertexRef, vcg::face::FFAdj, vcg::face::BitFlags > {};
24+
// class MyEdge : public vcg::Edge<MyUsedTypes>{};
25+
// class MyMesh : public vcg::tri::TriMesh< std::vector<MyVertex>, std::vector<MyFace> , std::vector<MyEdge> > {};
26+
27+
// char *buf=0;
28+
// int size;
29+
// int vertexNum=0;
30+
31+
// extern "C" {
32+
// char * allocator(size_t _size)
33+
// {
34+
// size = _size;
35+
// buf = (char *) malloc(size);
36+
// return buf;
37+
// }
38+
39+
// int getVertexNumber(){ return vertexNum; }
40+
41+
// int* getVertexes() {
42+
// MyMesh m;
43+
// int t0=clock();
44+
// int loadmask;
45+
46+
// int ret = tri::io::ImporterOFF<MyMesh>::OpenMem(m,buf,strlen(buf),loadmask);
47+
// int t1=clock();
48+
// if(ret != 0)
49+
// {
50+
// printf("Error in opening file\n");
51+
// exit(-1);
52+
// }
53+
// int t2=clock();
54+
// printf("Read mesh %i %i\n",m.FN(),m.VN());
55+
// vertexNum=n.VN();
56+
57+
// return v;
58+
// }
59+
// }
60+
61+
2362
#include <stdlib.h>
63+
#include <vector>
2464
#include <emscripten.h>
2565
#include <emscripten/bind.h>
26-
#include <vcg/complex/complex.h>
27-
#include <wrap/io_trimesh/import_off.h>
28-
#include <wrap/io_trimesh/export_off.h>
2966

30-
#include <vcg/complex/algorithms/refine.h>
31-
using namespace vcg;
3267
using namespace std;
3368
using namespace emscripten;
3469

70+
extern "C" {
71+
struct vert {
72+
int x;
73+
int y;
74+
};
3575

36-
class MyEdge;
37-
class MyFace;
38-
class MyVertex;
39-
struct MyUsedTypes : public vcg::UsedTypes< vcg::Use<MyVertex> ::AsVertexType,
40-
vcg::Use<MyEdge> ::AsEdgeType,
41-
vcg::Use<MyFace> ::AsFaceType>{};
42-
43-
class MyVertex : public vcg::Vertex<MyUsedTypes, vcg::vertex::Coord3f, vcg::vertex::Normal3f, vcg::vertex::Color4b, vcg::vertex::Qualityf, vcg::vertex::BitFlags >{};
44-
class MyFace : public vcg::Face< MyUsedTypes, vcg::face::Normal3f, vcg::face::VertexRef, vcg::face::FFAdj, vcg::face::BitFlags > {};
45-
class MyEdge : public vcg::Edge<MyUsedTypes>{};
46-
class MyMesh : public vcg::tri::TriMesh< std::vector<MyVertex>, std::vector<MyFace> , std::vector<MyEdge> > {};
47-
48-
char *buf=0;
49-
int size;
50-
51-
extern "C"
52-
{
53-
char * allocator(size_t _size)
54-
{
55-
size = _size;
56-
buf = (char *) malloc(size);
57-
return buf;
58-
}
59-
76+
int getLength(){ return 6; }
6077

61-
int * refine()
62-
{
63-
int* v = new int[3];
64-
v[0]=1;
65-
v[1]=2;
66-
v[2]=4;
67-
// vector<int> v;
68-
// v.push_back(2);
69-
// v.push_back(4);
70-
// v.push_back(3);
78+
vert* getVector() {
79+
vert* v = new vert[3];
80+
v[0].x=2;
81+
v[0].y=22;
82+
v[1].x=4;
83+
v[1].y=44;
84+
v[2].x=6;
85+
v[2].y=66;
7186
return v;
7287
}
7388
}
7489

75-
76-
77-
// EMSCRIPTEN_BINDINGS(foo){
78-
// // // register_vector<int>("v");
79-
// emscripten::function("refine",&refine);
80-
// }
81-
90+
8291

8392

‎test/LoadProcRender1/refine.js

+301-298
Large diffs are not rendered by default.

‎test/PassArrayCppToEmScripten/build.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
# source emsdk_set_env.sh
33

44
#my local path
5-
em++ -I /Users/maurizio/Desktop/Universita/F3D/vcg-code/vcglib/ refine.cpp -s EXPORTED_FUNCTIONS="['_allocator','_refine']" -o refine.js
6-
#em++ -I ../../../vcglib/ refine.cpp -s EXPORTED_FUNCTIONS="['_allocator','_refine']" -o refine.js
5+
em++ --bind -I /Users/maurizio/Desktop/Universita/F3D/vcg-code/vcglib/ refine.cpp -s EXPORTED_FUNCTIONS="['_getLength','_getVector']" -o refine.js
6+
#em++ -I ../../../vcglib/ refine.cpp -s EXPORTED_FUNCTIONS="['_allocator','_refine']" -o refine.js
7+
# em++ refine.cpp --bind -o refine.js

‎test/PassArrayCppToEmScripten/index.html

+14-37
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@
44
<head>
55
<meta charset="utf-8">
66
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
7-
<title>LoadProc</title>
7+
<title>passing array....</title>
88
</head>
99

1010
<body>
1111
<input type="file" id="files" name="files[]" value="tetra.off" />
1212
<br>
1313
<output id="list"></output>
1414
<textarea id="output" rows="8"></textarea>
15+
<form>
16+
Mesh name:<br>
17+
<input type="text" id="name_mesh" name="mesh_name" value="mesh.off">
18+
<br>
19+
</form>
20+
<button id='save_mesh' style="display:none;">Save Mesh</button>
1521
<script type='text/javascript'>
1622
/*
1723
Module is a global JavaScript object with attributes that
@@ -35,7 +41,7 @@
3541
//text = text.replace(/</g, "&lt;");
3642
//text = text.replace(/>/g, "&gt;");
3743
//text = text.replace('\n', '<br>', 'g');
38-
console.log(text);
44+
// console.log(text);
3945
if (element) {
4046
element.value += text + "\n";
4147
element.scrollTop = element.scrollHeight; // focus on bottom
@@ -48,44 +54,15 @@
4854
<script type="text/javascript" src="refine.js"></script>
4955

5056
<script type="text/javascript">
51-
52-
function handleFileSelect(evt) {
53-
var files = evt.target.files; // FileList object
54-
console.log("Name: ", files[0].name);
55-
console.log("Size: ", files[0].size);
56-
var result = Module.ccall('allocator', // name of C function
57+
var result = Module.ccall('getVector',
5758
'number', // return type
5859
['number'], // argument types
59-
[files[0].size]); // arguments
60-
console.time("File Reading Time");
61-
62-
var fileToLoad = files[0];
63-
var fileReader = new FileReader();
64-
65-
66-
fileReader.onload = function (fileLoadedEvent) {
67-
var textFromFileLoaded = fileLoadedEvent.target.result;
68-
console.log("Read file", textFromFileLoaded.length);
69-
Module.writeStringToMemory(textFromFileLoaded, result);
70-
console.timeEnd("File Reading Time");
71-
console.time("Refinement Time");
72-
var result1 = Module.ccall('refine',
73-
'number', // return type
74-
['number'], // argument types
7560
[1]);
76-
console.timeEnd("Refinement Time");
77-
// for(var i=0; i<result.length; i++){
78-
console.log(result1);
79-
var res=Module.getValue(result, 'double');
80-
console.log(res);
81-
console.log(res);
82-
83-
// }
84-
};
85-
fileReader.readAsText(fileToLoad, "UTF-8");
86-
}
87-
document.getElementById('files').addEventListener('change', handleFileSelect, false);
88-
61+
var length = Module.ccall('getLength','number');
62+
console.log("pointer "+result);
63+
console.log("length vector "+length);
64+
for(var i=0; i<length; i++)
65+
console.log(Module.getValue(result+parseInt(i*4),'*'));
8966
</script>
9067
</body>
9168
</html>

0 commit comments

Comments
 (0)