DXF jest całkiem prosty. Zamieszczam funkcję ze scan_extract która robi właściwie to samo - tu jest to bardziej skomplikowane, bo jest możliwość opuszczania vert_avg wierszy i horiz_avg kolumn, i jeszcze w ostatniej podwójnej pętli jeśli rotate_b == true, to koniec płata zostanie połączony z początkiem. Wyliczone współrzędne (x, y, z) są już w tablicy tablic vertices (w każdym wierszu trzy kolejne liczby to (x, y, z) (więc trzeba najpierw "stablicować" punkty utworzone z bitmapy, jednym pzebiegiem nie da rady).
Zresztą ac3d jest równie łatwy, a stl chyba najłatwiejszy - specyfikacja ma jakieś trzy strony.
Kod: Zaznacz cały
void
outputFramesDxf ( int num_points, int num_frames, float ** vertices )
{
int horiz_avg = Image::settings().horiz_avg ;
int vert_avg = Image::settings().vert_avg ;
int num_outframes = num_frames / horiz_avg ;
int num_outpoints = num_points / vert_avg ;
float * avg = new float [ num_outpoints * num_outframes * 3 ] ;
ofstream out_file ;
out_file.open ( outfile_fullpath.c_str() ) ;
if ( ! out_file.is_open() ) {
cerr << outfile_fullpath << " is not open!" << endl ;
return ;
}
/* set fixed */
//out_file << fixed << setprecision ( 6 ) ;
out_file << "0\nSECTION\n2\nENTITIES" << endl ;
/*
out_file << "999\n Cols " << num_frames << " -> " << num_outframes <<
"\n999\n Rows " << num_points << " -> " << num_outpoints << endl ;
out_file << "999\n VERTEXES: " << num_outpoints * num_outframes << endl ;
*/
for ( int f = 0 ; f < num_outframes ; ++f )
for ( int i = 0 ; i < num_outpoints ; ++i )
{
int index = ( f * num_outpoints + i ) * 3 ;
avg [ index ] = avg [ index + 1 ] = avg [ index + 2 ] = 0.0 ;
for ( int ff = 0 ; ff < horiz_avg ; ++ff )
for ( int ii = 0 ; ii < vert_avg ; ++ii )
{
int fhff = f * horiz_avg + ff ;
int ivii = ( i * vert_avg + ii ) * 3 ;
avg [ index ] += vertices [ fhff ] [ ivii ] ;
avg [ index + 1 ] += vertices [ fhff ] [ ivii + 1 ] ;
avg [ index + 2 ] += vertices [ fhff ] [ ivii + 2 ] ;
}
avg [ index ] /= (float) ( horiz_avg * vert_avg ) ;
avg [ index + 1 ] /= (float) ( horiz_avg * vert_avg ) ;
avg [ index + 2 ] /= (float) ( horiz_avg * vert_avg ) ;
}
int n_of ;
if ( Image::settings().rotate_b == true ) {
n_of = num_outframes ;
// out_file << "999\n(rotate) SURFACES: " <<
// num_outframes * ( num_outpoints - 1 ) * 2 << endl ;
} else {
//num_outframes -- ;
n_of = num_outframes - 1 ;
// out_file << "999\n(move) SURFACES: " <<
// ( num_outframes - 1 ) * ( num_outpoints - 1 ) * 2 << endl ;
}
for ( int f = 0 ; f < n_of ; ++ f )
{
int ff = ( f == num_outframes - 1 ) ? 0 : f + 1 ;
for ( int i = 0 ; i < num_outpoints - 1 ; ++ i )
{
int ii = i + 1 ;
int i_fi = ( f * num_outpoints + i ) * 3 ;
int i_ffi = ( ff * num_outpoints + i ) * 3 ;
int i_ffii = ( ff * num_outpoints + ii ) * 3 ;
int i_fii = ( f * num_outpoints + ii ) * 3 ;
// trójkąt 1: (ff,ii) (ff,i) (f,i)
out_file << "0\n3DFACE\n8\nscan3d" << endl ;
// 10, 20, 30 -> x, y, z pierwszego punktu ff ii
out_file << "10\n" << avg [ i_ffii ] <<
"\n20\n" << avg [ i_ffii + 1 ] <<
"\n30\n" << avg [ i_ffii + 2 ] << endl ;
// 11, 21, 31 -> x, y, z drugiego punktu ff i
out_file << "11\n" << avg [ i_ffi ] <<
"\n21\n" << avg [ i_ffi + 1 ] <<
"\n31\n" << avg [ i_ffi + 2 ] << endl ;
// 12, 22, 32 -> x, y, z trzeciego punktu f i
out_file << "12\n" << avg [ i_fi ] <<
"\n22\n" << avg [ i_fi + 1 ] <<
"\n32\n" << avg [ i_fi + 2 ] << endl ;
// 13, 23, 33 -> x, y, z czwartego punktu f i
out_file << "13\n" << avg [ i_fi ] <<
"\n23\n" << avg [ i_fi + 1 ] <<
"\n33\n" << avg [ i_fi + 2 ] << endl ;
// trójkąt 2: (f,ii) (ff,ii) (f,i)
out_file << "0\n3DFACE\n8\nscan3d" << endl ;
// 10, 20, 30 -> x, y, z pierwszego punktu f ii
out_file << "10\n" << avg [ i_fii ] <<
"\n20\n" << avg [ i_fii + 1 ] <<
"\n30\n" << avg [ i_fii + 2 ] << endl ;
// 11, 21, 31 -> x, y, z drugiego punktu ff ii
out_file << "11\n" << avg [ i_ffii ] <<
"\n21\n" << avg [ i_ffii + 1 ] <<
"\n31\n" << avg [ i_ffii + 2 ] << endl ;
// 12, 22, 32 -> x, y, z trzeciego punktu f i
out_file << "12\n" << avg [ i_fi ] <<
"\n22\n" << avg [ i_fi + 1 ] <<
"\n32\n" << avg [ i_fi + 2 ] << endl ;
// 13, 23, 33 -> x, y, z czwartego punktu f i
out_file << "13\n" << avg [ i_fi ] <<
"\n23\n" << avg [ i_fi + 1 ] <<
"\n33\n" << avg [ i_fi + 2 ] << endl ;
}
}
out_file << "0\nENDSEC\n0\nEOF" << endl ;
out_file.close() ;
delete [] avg ;
}