45 #define _USE_MATH_DEFINES
53 #include <QTextStream>
60 using namespace UTILSLIB;
61 using namespace Eigen;
76 QList<QVector<float> > &outputPoints,
77 const QStringList &names,
95 float xmin,xmax,ymin,ymax;
97 int nchan = inputPoints.size();
99 MatrixXf rrs(nchan,3);
104 std::cout <<
"No input points to lay out.\n";
109 for(
k = 0;
k<nchan;
k++) {
110 rrs(
k,0) = inputPoints.at(
k)[0];
111 rrs(
k,1) = inputPoints.at(
k)[1];
112 rrs(
k,2) = inputPoints.at(
k)[2];
115 std::cout <<
"Channels found for layout: " << nchan <<
"\n";
119 std::cout <<
"Using default origin:" << r0[0] <<
", " << r0[1] <<
", " << r0[2] <<
"\n";
127 std::cout <<
"best fitting sphere:\n";
128 std::cout <<
"torigin: " << r0[0] <<
", " << r0[1] <<
", " << r0[2] << std::endl <<
"; tradius: " << rad <<
"\n";
134 for (
k = 0;
k < nchan;
k++) {
135 rr = r0 -
static_cast<VectorXf
>(rrs.row(
k));
136 sphere_coord(rr[0],rr[1],rr[2],&rad,&th,&phi);
137 xx[
k] = prad*(2.0*th/M_PI)*cos(phi);
138 yy[
k] = prad*(2.0*th/M_PI)*sin(phi);
147 for(
k = 1;
k < nchan;
k++) {
150 else if (xx[
k] < xmin)
154 else if (yy[
k] < ymin)
158 if(xmin == xmax || ymin == ymax) {
159 std::cout<<
"Cannot make a layout. All positions are identical\n";
172 QVector<float> point;
176 if (!outFile.open(QIODevice::WriteOnly)) {
177 std::cout <<
"Could not open output file!\n";
181 out.setDevice(&outFile);
184 #if QT_VERSION > QT_VERSION_CHECK(6, 0, 0)
188 out <<
"0.000000 0.000000 0.000000 0.000000" << endl;
190 for(
k = 0;
k < nchan;
k++) {
194 point.append(-(xx[
k]-0.5*w));
196 point.append(xx[
k]-0.5*w);
199 point.append(-(yy[
k]-0.5*h));
201 point.append(yy[
k]-0.5*h);
203 outputPoints.append(point);
206 if(
k < names.size()) {
207 out <<
k+1 <<
" " << point[0] <<
" " << point[1] <<
" " << w <<
" " << h <<
" " << names.at(
k) << endl;
209 out <<
k+1 <<
" " << point[0] <<
" " << point[1] <<
" " << w <<
" " << h << endl;
215 std::cout <<
"Success while wrtiting to output file.\n";
226 std::vector<std::vector<float> > &outputPoints,
227 const std::vector<std::string> &names,
228 const std::string& outFilePath,
245 float xmin,xmax,ymin,ymax;
246 int nchan = inputPoints.size();
248 MatrixXf rrs(nchan,3);
253 std::cout <<
"No input points to lay out.\n";
258 for(
int k = 0;
k < nchan;
k++) {
259 rrs(
k,0) = inputPoints.at(
k)[0];
260 rrs(
k,1) = inputPoints.at(
k)[1];
261 rrs(
k,2) = inputPoints.at(
k)[2];
264 std::cout <<
"Channels found for layout: " << nchan <<
"\n";
268 std::cout <<
"Using default origin:" << r0[0] <<
", " << r0[1] <<
", " << r0[2] <<
"\n";
276 std::cout <<
"best fitting sphere:\n";
277 std::cout <<
"torigin: " << r0[0] <<
", " << r0[1] <<
", " << r0[2] << std::endl <<
"; tradius: " << rad <<
"\n";
283 for (
int k = 0;
k < nchan;
k++) {
284 rr = r0 -
static_cast<VectorXf
>(rrs.row(
k));
285 sphere_coord(rr[0],rr[1],rr[2],&rad,&th,&phi);
286 xx[
k] = prad*(2.0*th/M_PI)*cos(phi);
287 yy[
k] = prad*(2.0*th/M_PI)*sin(phi);
296 for(
int k = 1;
k < nchan;
k++) {
299 else if (xx[
k] < xmin)
303 else if (yy[
k] < ymin)
307 if(xmin == xmax || ymin == ymax) {
308 std::cout<<
"Cannot make a layout. All positions are identical\n";
321 std::vector<float> point;
322 std::ofstream outFile;
325 outFile.open(outFilePath);
326 if (outFile.is_open()) {
327 std::cout <<
"Could not open output file!\n";
330 outFile <<
"0.000000 0.000000 0.000000 0.000000" << std::endl;
333 for(
int k = 0;
k < nchan;
k++) {
337 point.push_back(-(xx[
k]-0.5*w));
339 point.push_back(xx[
k]-0.5*w);
342 point.push_back(-(yy[
k]-0.5*h));
344 point.push_back(yy[
k]-0.5*h);
346 outputPoints.push_back(point);
349 if((
k) < (
int)names.size()) {
350 outFile <<
k+1 <<
" " << point[0] <<
" " << point[1] <<
" " << w <<
" " << h <<
" " << names.at(
k) << std::endl;
352 outFile <<
k+1 <<
" " << point[0] <<
" " << point[1] <<
" " << w <<
" " << h << std::endl;
358 std::cout <<
"Success while wrtiting to output file.\n";
366 void LayoutMaker::sphere_coord (
float x,
374 float rxy = sqrt(x*x+y*y);
381 *r = sqrt(x*x+y*y+z*z);
382 *theta = acos(z/(*r));
385 *phi = *phi + 2.0*M_PI;