ファイル情報

Rev. 449
サイズ 20,752 バイト
日時 2012-03-06 23:38:12
作者 rishitani
ログメッセージ

(メッセージはありません)

内容

  1. // -*-Mode: C++;-*-
  2. //
  3. // Generate/Render a mesh contour of ScalarObject
  4. //
  5. // $Id: MapMeshRenderer.cpp,v 1.13 2011/02/03 10:39:51 rishitani Exp $
  6. //
  7. #include <common.h>
  8. #include "MapMeshRenderer.hpp"
  9. #include "DensityMap.hpp"
  10. #include <gfx/DisplayContext.hpp>
  11. #include <qsys/ScrEventManager.hpp>
  12. #include <qsys/ViewEvent.hpp>
  13. #include <qsys/View.hpp>
  14. #include <qsys/Scene.hpp>
  15. #include <modules/molstr/AtomIterator.hpp>
  16. #define SCALE 0x1000
  17. //#define DBG_DRAW_AXIS 0
  18. using namespace xtal;
  19. using qlib::Matrix4D;
  20. using qlib::Matrix3D;
  21. using qsys::ScrEventManager;
  22. using molstr::AtomIterator;
  23. // default constructor
  24. MapMeshRenderer::MapMeshRenderer()
  25. : super_t()
  26. {
  27. m_pXCrsLst = NULL;
  28. m_pYCrsLst = NULL;
  29. m_pZCrsLst = NULL;
  30. m_nBufSize = 100;
  31. m_lw = 1.0;
  32. m_bPBC = false;
  33. m_bAutoUpdate = true;
  34. //resetAllProps();
  35. // default work area size 100x100x100
  36. setCrossArraySize(m_nBufSize,m_nBufSize,m_nBufSize);
  37. m_bUseMolBndry = false;
  38. }
  39. // destructor
  40. MapMeshRenderer::~MapMeshRenderer()
  41. {
  42. if (m_pXCrsLst!=NULL)
  43. delete m_pXCrsLst;
  44. if (m_pYCrsLst!=NULL)
  45. delete m_pYCrsLst;
  46. if (m_pZCrsLst!=NULL)
  47. delete m_pZCrsLst;
  48. //if (m_pdl!=NULL)
  49. //delete m_pdl;
  50. // for safety, remove from event manager is needed here...
  51. ScrEventManager *pSEM = ScrEventManager::getInstance();
  52. pSEM->removeViewListener(this);
  53. }
  54. /////////////////////////////////
  55. const char *MapMeshRenderer::getTypeName() const
  56. {
  57. return "contour";
  58. }
  59. /////////////////////////////////
  60. void MapMeshRenderer::setBufSize(int nsize)
  61. {
  62. if (nsize<=10)
  63. nsize = 10;
  64. m_nBufSize = nsize;
  65. setCrossArraySize(m_nBufSize,m_nBufSize,m_nBufSize);
  66. }
  67. bool MapMeshRenderer::setCrossArraySize(int ncol, int nrow, int nsec)
  68. {
  69. if (m_pXCrsLst!=NULL)
  70. delete m_pXCrsLst;
  71. if (m_pYCrsLst!=NULL)
  72. delete m_pYCrsLst;
  73. if (m_pZCrsLst!=NULL)
  74. delete m_pZCrsLst;
  75. m_nColCrs = ncol; m_nRowCrs = nrow; m_nSecCrs = nsec;
  76. m_pXCrsLst = new qlib::ByteMap(ncol, nrow, nsec);
  77. m_pYCrsLst = new qlib::ByteMap(ncol, nrow, nsec);
  78. m_pZCrsLst = new qlib::ByteMap(ncol, nrow, nsec);
  79. if (m_pXCrsLst==NULL||
  80. m_pYCrsLst==NULL||
  81. m_pZCrsLst==NULL)
  82. return false;
  83. return true;
  84. }
  85. unsigned char MapMeshRenderer::getContSec(unsigned int s0,
  86. unsigned int s1,
  87. unsigned int lv)
  88. {
  89. double crs;
  90. bool flag = false;
  91. if ( s0!=s1 ) {
  92. if (s0<lv && lv<s1) { // s0 < lv < s1
  93. crs = double(lv-s0)/double(s1-s0);
  94. flag = true;
  95. }
  96. else if (s1<lv && lv<s0) { // s1 < lv < s0
  97. crs = double(s0-lv)/double(s0-s1);
  98. flag = true;
  99. }
  100. else if((lv==s0 || lv==s1) &&
  101. (lv>=s0 && lv>=s1)) {
  102. if (lv==s0)
  103. crs = m_delta/double(s0-s1);
  104. else
  105. crs = double(lv-s0)/(double(s1-s0)+m_delta);
  106. flag = true;
  107. }
  108. }
  109. if (flag==false)
  110. return 0;
  111. //MB_DPRINT("(%d %d)/%d contour sec %f\n",s0, s1, lv, crs);
  112. crs *= 254.0f;
  113. if (crs<=0)
  114. return 1;
  115. else if (crs>=254)
  116. return 255;
  117. unsigned char bcrs = (unsigned char)crs;
  118. bcrs++;
  119. return bcrs;
  120. }
  121. bool MapMeshRenderer::generate(ScalarObject *pMap, DensityMap *pXtal)
  122. {
  123. const Vector4D cent = getCenter();
  124. const double siglevel = getSigLevel();
  125. const double extent = getExtent();
  126. if (pMap==NULL)
  127. return false;
  128. // check and setup mol boundary data
  129. setupMolBndry();
  130. // calculate the contour level
  131. const double level = pMap->getRmsdDensity() * siglevel;
  132. double lvtmp = floor( (level-pMap->getLevelBase()) / pMap->getLevelStep() * SCALE );
  133. unsigned int lv = (unsigned int)lvtmp;
  134. if (lvtmp<0) lv = 0;
  135. if (lvtmp>0xFF*SCALE) lv = 0xFF*SCALE;
  136. m_delta = pMap->getRmsdDensity()*0.01;
  137. //
  138. // col,row,sec
  139. //
  140. Vector4D vmin(cent.x()-extent, cent.y()-extent, cent.z()-extent);
  141. Vector4D vmax(cent.x()+extent, cent.y()+extent, cent.z()+extent);
  142. //Vector4D vmin(-1000,-1000,-1000),
  143. // vmax(1000,1000,1000);
  144. // get origin / translate the origin to (0,0,0)
  145. vmin -= pMap->getOrigin();
  146. vmax -= pMap->getOrigin();
  147. if (pXtal!=NULL) {
  148. const CrystalInfo &xt = pXtal->getXtalInfo();
  149. xt.orthToFrac(vmin);
  150. xt.orthToFrac(vmax);
  151. // check PBC
  152. m_bPBC = false;
  153. const double dimx = pMap->getColGridSize()*pMap->getColNo();
  154. const double dimy = pMap->getRowGridSize()*pMap->getRowNo();
  155. const double dimz = pMap->getSecGridSize()*pMap->getSecNo();
  156. const double cea = xt.a();
  157. const double ceb = xt.b();
  158. const double cec = xt.c();
  159. if (qlib::isNear4(dimx, cea) &&
  160. qlib::isNear4(dimy, ceb) &&
  161. qlib::isNear4(dimz, cec))
  162. m_bPBC = true;
  163. }
  164. if (pXtal!=NULL) {
  165. vmin.x() *= pXtal->getColInterval();
  166. vmin.y() *= pXtal->getRowInterval();
  167. vmin.z() *= pXtal->getSecInterval();
  168. vmax.x() *= pXtal->getColInterval();
  169. vmax.y() *= pXtal->getRowInterval();
  170. vmax.z() *= pXtal->getSecInterval();
  171. }
  172. else {
  173. vmin.x() /= pMap->getColGridSize();
  174. vmin.y() /= pMap->getRowGridSize();
  175. vmin.z() /= pMap->getSecGridSize();
  176. vmax.x() /= pMap->getColGridSize();
  177. vmax.y() /= pMap->getRowGridSize();
  178. vmax.z() /= pMap->getSecGridSize();
  179. }
  180. if (!m_bPBC) {
  181. // limit XYZ in the available region of map
  182. vmin.x() = floor(qlib::max<double>(vmin.x(), pMap->getStartCol()));
  183. vmin.y() = floor(qlib::max<double>(vmin.y(), pMap->getStartRow()));
  184. vmin.z() = floor(qlib::max<double>(vmin.z(), pMap->getStartSec()));
  185. vmax.x() = floor(qlib::min<double>(vmax.x(), pMap->getStartCol()+pMap->getColNo()));
  186. vmax.y() = floor(qlib::min<double>(vmax.y(), pMap->getStartRow()+pMap->getRowNo()));
  187. vmax.z() = floor(qlib::min<double>(vmax.z(), pMap->getStartSec()+pMap->getSecNo()));
  188. }
  189. m_nMapColNo = pMap->getColNo();
  190. m_nMapRowNo = pMap->getRowNo();
  191. m_nMapSecNo = pMap->getSecNo();
  192. Vector4D vwi;
  193. vwi.x() = vmax.x() - vmin.x();
  194. vwi.y() = vmax.y() - vmin.y();
  195. vwi.z() = vmax.z() - vmin.z();
  196. if (vwi.x() >= m_nColCrs) {
  197. int dif = int(vwi.x() - m_nColCrs);
  198. if (dif%2==0)
  199. dif /= 2;
  200. else
  201. dif = dif/2+1;
  202. vmin.x() += dif;
  203. vmax.x() -= dif;
  204. }
  205. if (vwi.y() >= m_nRowCrs) {
  206. int dif = int(vwi.y() - m_nRowCrs);
  207. if (dif%2==0)
  208. dif /= 2;
  209. else
  210. dif = dif/2+1;
  211. vmin.y() += dif;
  212. vmax.y() -= dif;
  213. }
  214. if (vwi.z() >= m_nSecCrs) {
  215. int dif = int(vwi.z() - m_nSecCrs);
  216. if (dif%2==0)
  217. dif /= 2;
  218. else
  219. dif = dif/2+1;
  220. vmin.z() += dif;
  221. vmax.z() -= dif;
  222. }
  223. int ncol = int(vmax.x() - vmin.x());
  224. int nrow = int(vmax.y() - vmin.y());
  225. int nsec = int(vmax.z() - vmin.z());
  226. int stcol = int(vmin.x())-pMap->getStartCol();
  227. int strow = int(vmin.y())-pMap->getStartRow();
  228. int stsec = int(vmin.z())-pMap->getStartSec();
  229. MB_DPRINT("ncol_cross: %d\n", m_nColCrs);
  230. MB_DPRINT("nrow_cross: %d\n", m_nRowCrs);
  231. MB_DPRINT("nsec_cross: %d\n", m_nSecCrs);
  232. MB_DPRINT("ncol: %d\n", ncol);
  233. MB_DPRINT("nrow: %d\n", nrow);
  234. MB_DPRINT("nsec: %d\n", nsec);
  235. // MB_DPRINT("col: %f - %f\n",vmin.x(),vmax.x());
  236. // MB_DPRINT("row: %f - %f\n",vmin.y(),vmax.y());
  237. // MB_DPRINT("sec: %f - %f\n",vmin.z(),vmax.z());
  238. // MB_DPRINT("stcol: %d\n",stcol);
  239. // MB_DPRINT("strow: %d\n",strow);
  240. // MB_DPRINT("stsec: %d\n",stsec);
  241. int i,j,k;
  242. //
  243. // generate X(column) direction contour section
  244. //
  245. MB_DPRINTLN("Xdir contour gen start");
  246. unsigned char crs;
  247. unsigned int s0,s1;
  248. for (k=0; k<nsec; k++)
  249. for (j=0; j<nrow; j++)
  250. for (i=0; i<ncol-1; i++){
  251. s0 = getMap(pMap, stcol+i, strow+j,stsec+k)*SCALE;
  252. s1 = getMap(pMap, stcol+i+1,strow+j,stsec+k)*SCALE;
  253. crs = getContSec(s0, s1, lv);
  254. if (crs!=0) {
  255. if (!inMolBndry(pMap, stcol+i, strow+j,stsec+k) ||
  256. !inMolBndry(pMap, stcol+i+1,strow+j,stsec+k))
  257. crs=0;
  258. }
  259. m_pXCrsLst->at(i,j,k) = crs;
  260. }
  261. /////////////////////////////////////////////
  262. MB_DPRINTLN("Ydir contour gen start");
  263. for (k=0; k<nsec; k++)
  264. for (i=0; i<ncol; i++)
  265. for (j=0; j<nrow-1; j++) {
  266. s0 = getMap(pMap, stcol+i,strow+j, stsec+k)*SCALE;
  267. s1 = getMap(pMap, stcol+i,strow+j+1,stsec+k)*SCALE;
  268. crs = getContSec(s0, s1, lv);
  269. if (crs!=0) {
  270. if (!inMolBndry(pMap, stcol+i,strow+j ,stsec+k) ||
  271. !inMolBndry(pMap, stcol+i,strow+j+1,stsec+k))
  272. crs = 0;
  273. }
  274. m_pYCrsLst->at(i,j,k) = crs;
  275. }
  276. /////////////////////////////////////////////
  277. MB_DPRINTLN("Zdir contour gen start");
  278. for (j=0; j<nrow; j++)
  279. for (i=0; i<ncol; i++)
  280. for (k=0; k<nsec-1; k++){
  281. s0 = getMap(pMap, stcol+i,strow+j,stsec+k)*SCALE;
  282. s1 = getMap(pMap, stcol+i,strow+j,stsec+k+1)*SCALE;
  283. crs = getContSec(s0, s1, lv);
  284. if (crs!=0) {
  285. if (!inMolBndry(pMap, stcol+i,strow+j,stsec+k) ||
  286. !inMolBndry(pMap, stcol+i,strow+j,stsec+k+1))
  287. crs = 0;
  288. }
  289. m_pZCrsLst->at(i,j,k) = crs;
  290. }
  291. m_nActCol = ncol;
  292. m_nActRow = nrow;
  293. m_nActSec = nsec;
  294. m_nStCol = int(vmin.x());
  295. m_nStRow = int(vmin.y());
  296. m_nStSec = int(vmin.z());
  297. return true;
  298. }
  299. namespace {
  300. inline void drawline(DisplayContext *pdl,
  301. float x1, float y1, float z1,
  302. float x2, float y2, float z2)
  303. {
  304. pdl->vertex(x1, y1, z1);
  305. pdl->vertex(x2, y2, z2);
  306. }
  307. }
  308. void MapMeshRenderer::preRender(DisplayContext *pdc)
  309. {
  310. pdc->color(getColor());
  311. pdc->setLineWidth(m_lw);
  312. pdc->setLighting(false);
  313. }
  314. // generate display list
  315. void MapMeshRenderer::render(DisplayContext *pdl)
  316. {
  317. if (m_pXCrsLst==NULL ||
  318. m_pYCrsLst==NULL ||
  319. m_pZCrsLst==NULL)
  320. return;
  321. ScalarObject *pMap = static_cast<ScalarObject *>(getClientObj().get());
  322. DensityMap *pXtal = dynamic_cast<DensityMap *>(pMap);
  323. if (!generate(pMap, pXtal))
  324. return;
  325. //
  326. // setup frac-->orth matrix
  327. //
  328. int ncol = m_nActCol; //m_nColCrs;
  329. int nrow = m_nActRow; //m_nRowCrs;
  330. int nsec = m_nActSec; //m_nSecCrs;
  331. pdl->pushMatrix();
  332. if (pXtal==NULL)
  333. pdl->translate(pMap->getOrigin());
  334. if (pXtal!=NULL) {
  335. Matrix3D orthmat = pXtal->getXtalInfo().getOrthMat();
  336. //orthmat.transpose();
  337. pdl->multMatrix(Matrix4D(orthmat));
  338. }
  339. #ifdef DBG_DRAW_AXIS
  340. pdl->startLines();
  341. // pdl->color(1,1,0);
  342. pdl->vertex(0,0,0);
  343. pdl->vertex(1,0,0);
  344. pdl->vertex(0,0,0);
  345. pdl->vertex(0,1,0);
  346. pdl->vertex(0,0,0);
  347. pdl->vertex(0,0,1);
  348. pdl->end();
  349. #endif
  350. {
  351. Vector4D vtmp;
  352. if (pXtal!=NULL)
  353. vtmp = Vector4D(1.0/double(pXtal->getColInterval()),
  354. 1.0/double(pXtal->getRowInterval()),
  355. 1.0/double(pXtal->getSecInterval()));
  356. else
  357. vtmp = Vector4D(pMap->getColGridSize(),
  358. pMap->getRowGridSize(),
  359. pMap->getSecGridSize());
  360. pdl->scale(vtmp);
  361. vtmp = Vector4D(m_nStCol, m_nStRow, m_nStSec);
  362. pdl->translate(vtmp);
  363. }
  364. MB_DPRINTLN("MapMeshRenderer Rendereing...\n");
  365. pdl->startLines();
  366. // generate X-Y plane contour lines
  367. for (int k=0; k<nsec-1; k++)
  368. for (int j=0; j<nrow-1; j++) {
  369. for (int i=0; i<ncol-1; i++){
  370. unsigned char s0, s1, s2, s3;
  371. s0 = m_pXCrsLst->at(i,j,k);
  372. s1 = m_pYCrsLst->at(i+1,j,k);
  373. s2 = m_pXCrsLst->at(i,j+1,k);
  374. s3 = m_pYCrsLst->at(i,j,k);
  375. if (s0==0&&s1==0&&s2==0&&s3==0)
  376. continue;
  377. if (s0!=0&&s1!=0&&s2!=0&&s3!=0) {
  378. // saddle point
  379. float rt0, rt1, rt2, rt3;
  380. rt0 = float(s0-1)/254.0f;
  381. rt1 = float(s1-1)/254.0f;
  382. rt2 = float(s2-1)/254.0f;
  383. rt3 = float(s3-1)/254.0f;
  384. drawline(pdl,
  385. float(i)+rt0,(float)j,(float)k,
  386. (float)i+1,float(j)+rt1,(float)k);
  387. drawline(pdl,
  388. float(i)+rt2,(float)j+1,(float)k,
  389. (float)i,float(j)+rt3,(float)k);
  390. continue;
  391. }
  392. if (s0!=0&&s1==0&&s2!=0&&s3==0) {
  393. // s0-->s2 line
  394. float rt0, rt2;
  395. rt0 = float(s0-1)/254.0f;
  396. rt2 = float(s2-1)/254.0f;
  397. drawline(pdl,
  398. float(i)+rt0,(float)j, (float) k,
  399. float(i)+rt2,(float)j+1,(float)k);
  400. continue;
  401. }
  402. if (s0==0&&s1!=0&&s2==0&&s3!=0) {
  403. // s1-->s3 line
  404. float rt1, rt3;
  405. rt1 = float(s1-1)/254.0f;
  406. rt3 = float(s3-1)/254.0f;
  407. drawline(pdl,
  408. (float)i, float(j)+rt3,(float)k,
  409. (float)i+1,float(j)+rt1,(float)k);
  410. continue;
  411. }
  412. if (s0!=0&&s1!=0&&s2==0&&s3==0) {
  413. // s0-->s1 line
  414. float rt0, rt1;
  415. rt0 = float(s0-1)/254.0f;
  416. rt1 = float(s1-1)/254.0f;
  417. drawline(pdl,
  418. float(i)+rt0,(float)j, (float)k,
  419. (float)i+1,float(j)+rt1,(float)k);
  420. continue;
  421. }
  422. if (s0==0&&s1!=0&&s2!=0&&s3==0) {
  423. // s1-->s2 line
  424. float rt1, rt2;
  425. rt1 = float(s1-1)/254.0f;
  426. rt2 = float(s2-1)/254.0f;
  427. drawline(pdl,
  428. i+1,float(j)+rt1,k,
  429. float(i)+rt2,j+1,k);
  430. continue;
  431. }
  432. if (s0==0&&s1==0&&s2!=0&&s3!=0) {
  433. // s2-->s3 line
  434. float rt2, rt3;
  435. rt2 = float(s2-1)/254.0f;
  436. rt3 = float(s3-1)/254.0f;
  437. drawline(pdl,
  438. float(i)+rt2,(float)j+1,(float)k,
  439. (float)i,float(j)+rt3, (float)k);
  440. continue;
  441. }
  442. if (s0!=0&&s1==0&&s2==0&&s3!=0) {
  443. // s3-->s0 line
  444. float rt0, rt3;
  445. rt0 = float(s0-1)/254.0f;
  446. rt3 = float(s3-1)/254.0f;
  447. drawline(pdl,
  448. float(i)+rt0,(float)j,(float)k,
  449. (float)i,float(j)+rt3,(float)k);
  450. continue;
  451. }
  452. }
  453. }
  454. // generate Y-Z (or j-k) plane contour lines
  455. // --> X(i) is slow axis!
  456. for (int i=0; i<ncol-1; i++)
  457. for (int k=0; k<nsec-1; k++){
  458. for (int j=0; j<nrow-1; j++) {
  459. unsigned char s0, s1, s2, s3;
  460. s0 = m_pYCrsLst->at(i,j,k);
  461. s1 = m_pZCrsLst->at(i,j+1,k);
  462. s2 = m_pYCrsLst->at(i,j,k+1);
  463. s3 = m_pZCrsLst->at(i,j,k);
  464. if (s0==0&&s1==0&&s2==0&&s3==0)
  465. continue;
  466. if (s0!=0&&s1!=0&&s2!=0&&s3!=0) {
  467. // saddle point
  468. float rt0, rt1, rt2, rt3;
  469. rt0 = float(s0-1)/254.0f;
  470. rt1 = float(s1-1)/254.0f;
  471. rt2 = float(s2-1)/254.0f;
  472. rt3 = float(s3-1)/254.0f;
  473. drawline(pdl,
  474. (float)i,float(j)+rt0,(float)k,
  475. (float)i,(float)j+1,float(k)+rt1);
  476. drawline(pdl,
  477. (float)i,float(j)+rt2,(float)k+1,
  478. (float)i,(float)j,float(k)+rt3);
  479. continue;
  480. }
  481. if (s0!=0&&s1==0&&s2!=0&&s3==0) {
  482. // s0-->s2 line
  483. float rt0, rt2;
  484. rt0 = float(s0-1)/254.0f;
  485. rt2 = float(s2-1)/254.0f;
  486. drawline(pdl,
  487. (float)i,float(j)+rt0,(float)k,
  488. (float)i,float(j)+rt2,(float)k+1);
  489. continue;
  490. }
  491. if (s0==0&&s1!=0&&s2==0&&s3!=0) {
  492. // s1-->s3 line
  493. float rt1, rt3;
  494. rt1 = float(s1-1)/254.0f;
  495. rt3 = float(s3-1)/254.0f;
  496. drawline(pdl,
  497. (float)i,(float)j, float(k)+rt3,
  498. (float)i,(float)j+1,float(k)+rt1);
  499. continue;
  500. }
  501. if (s0!=0&&s1!=0&&s2==0&&s3==0) {
  502. // s0-->s1 line
  503. float rt0, rt1;
  504. rt0 = float(s0-1)/254.0f;
  505. rt1 = float(s1-1)/254.0f;
  506. drawline(pdl,
  507. (float)i,float(j)+rt0,(float)k,
  508. (float)i,(float)j+1,float(k)+rt1);
  509. continue;
  510. }
  511. if (s0==0&&s1!=0&&s2!=0&&s3==0) {
  512. // s1-->s2 line
  513. float rt1, rt2;
  514. rt1 = float(s1-1)/254.0f;
  515. rt2 = float(s2-1)/254.0f;
  516. drawline(pdl,
  517. (float)i,(float)j+1,float(k)+rt1,
  518. (float)i,float(j)+rt2,(float)k+1);
  519. continue;
  520. }
  521. if (s0==0&&s1==0&&s2!=0&&s3!=0) {
  522. // s2-->s3 line
  523. float rt2, rt3;
  524. rt2 = float(s2-1)/254.0f;
  525. rt3 = float(s3-1)/254.0f;
  526. drawline(pdl,
  527. (float)i,float(j)+rt2,(float)k+1,
  528. (float)i,(float)j,float(k)+rt3);
  529. continue;
  530. }
  531. if (s0!=0&&s1==0&&s2==0&&s3!=0) {
  532. // s3-->s0 line
  533. float rt0, rt3;
  534. rt0 = float(s0-1)/254.0f;
  535. rt3 = float(s3-1)/254.0f;
  536. drawline(pdl,
  537. (float)i,float(j)+rt0,(float)k,
  538. (float)i,(float)j,float(k)+rt3);
  539. continue;
  540. }
  541. }
  542. }
  543. // generate Z-X (or k-i) plane contour lines
  544. // --> Y(j) is slow axis!
  545. for (int j=0; j<nrow-1; j++)
  546. for (int i=0; i<ncol-1; i++){
  547. for (int k=0; k<nsec-1; k++){
  548. unsigned char s0, s1, s2, s3;
  549. s0 = m_pZCrsLst->at(i,j,k);
  550. s1 = m_pXCrsLst->at(i,j,k+1);
  551. s2 = m_pZCrsLst->at(i+1,j,k);
  552. s3 = m_pXCrsLst->at(i,j,k);
  553. if (s0==0&&s1==0&&s2==0&&s3==0)
  554. continue;
  555. if (s0!=0&&s1!=0&&s2!=0&&s3!=0) {
  556. // saddle point
  557. float rt0, rt1, rt2, rt3;
  558. rt0 = float(s0-1)/254.0f;
  559. rt1 = float(s1-1)/254.0f;
  560. rt2 = float(s2-1)/254.0f;
  561. rt3 = float(s3-1)/254.0f;
  562. drawline(pdl,
  563. i,j,float(k)+rt0,
  564. float(i)+rt1,j,k+1);
  565. drawline(pdl,
  566. i+1,j,float(k)+rt2,
  567. float(i)+rt3,j,k);
  568. continue;
  569. }
  570. if (s0!=0&&s1==0&&s2!=0&&s3==0) {
  571. // s0-->s2 line
  572. float rt0, rt2;
  573. rt0 = float(s0-1)/254.0f;
  574. rt2 = float(s2-1)/254.0f;
  575. drawline(pdl,
  576. i,j,float(k)+rt0,
  577. i+1,j,float(k)+rt2);
  578. continue;
  579. }
  580. if (s0==0&&s1!=0&&s2==0&&s3!=0) {
  581. // s1-->s3 line
  582. float rt1, rt3;
  583. rt1 = float(s1-1)/254.0f;
  584. rt3 = float(s3-1)/254.0f;
  585. drawline(pdl,
  586. float(i)+rt3,j,k,
  587. float(i)+rt1,j,k+1);
  588. continue;
  589. }
  590. if (s0!=0&&s1!=0&&s2==0&&s3==0) {
  591. // s0-->s1 line
  592. float rt0, rt1;
  593. rt0 = float(s0-1)/254.0f;
  594. rt1 = float(s1-1)/254.0f;
  595. drawline(pdl,
  596. i,j,float(k)+rt0,
  597. float(i)+rt1,j,k+1);
  598. continue;
  599. }
  600. if (s0==0&&s1!=0&&s2!=0&&s3==0) {
  601. // s1-->s2 line
  602. float rt1, rt2;
  603. rt1 = float(s1-1)/254.0f;
  604. rt2 = float(s2-1)/254.0f;
  605. drawline(pdl,
  606. float(i)+rt1,j,k+1,
  607. i+1,j,float(k)+rt2);
  608. continue;
  609. }
  610. if (s0==0&&s1==0&&s2!=0&&s3!=0) {
  611. // s2-->s3 line
  612. float rt2, rt3;
  613. rt2 = float(s2-1)/254.0f;
  614. rt3 = float(s3-1)/254.0f;
  615. drawline(pdl,
  616. i+1,j,float(k)+rt2,
  617. float(i)+rt3,j,k);
  618. continue;
  619. }
  620. if (s0!=0&&s1==0&&s2==0&&s3!=0) {
  621. // s3-->s0 line
  622. float rt0, rt3;
  623. rt0 = float(s0-1)/254.0f;
  624. rt3 = float(s3-1)/254.0f;
  625. drawline(pdl,
  626. i,j,float(k)+rt0,
  627. float(i)+rt3,j,k);
  628. continue;
  629. }
  630. }
  631. }
  632. pdl->end();
  633. pdl->popMatrix();
  634. MB_DPRINTLN("MapMeshRenderer Rendereing OK\n");
  635. }
  636. double MapMeshRenderer::getMaxExtent() const
  637. {
  638. MapMeshRenderer *pthis = const_cast<MapMeshRenderer *>(this);
  639. ScalarObject *pMap = (ScalarObject *) pthis->getClientObj().get();
  640. const double xmax = m_nColCrs * pMap->getColGridSize() / 2.0;
  641. const double ymax = m_nRowCrs * pMap->getRowGridSize() / 2.0;
  642. const double zmax = m_nSecCrs * pMap->getSecGridSize() / 2.0;
  643. return qlib::min(xmax, qlib::min(ymax, zmax));
  644. }
  645. void MapMeshRenderer::setSceneID(qlib::uid_t nid)
  646. {
  647. super_t::setSceneID(nid);
  648. if (nid!=qlib::invalid_uid) {
  649. ScrEventManager *pSEM = ScrEventManager::getInstance();
  650. pSEM->addViewListener(nid, this);
  651. }
  652. }
  653. qlib::uid_t MapMeshRenderer::detachObj()
  654. {
  655. ScrEventManager *pSEM = ScrEventManager::getInstance();
  656. pSEM->removeViewListener(this);
  657. return super_t::detachObj();
  658. }
  659. void MapMeshRenderer::viewChanged(qsys::ViewEvent &ev)
  660. {
  661. const int nType = ev.getType();
  662. if (nType!=qsys::ViewEvent::VWE_PROPCHG &&
  663. nType!=qsys::ViewEvent::VWE_PROPCHG_DRG)
  664. return;
  665. if (!m_bAutoUpdate && !m_bDragUpdate)
  666. return;
  667. if (!ev.getDescr().equals("center"))
  668. return;
  669. qsys::View *pView = ev.getTargetPtr();
  670. if (pView==NULL)
  671. return;
  672. Vector4D c = pView->getViewCenter();
  673. if (m_bDragUpdate) {
  674. if (nType==qsys::ViewEvent::VWE_PROPCHG ||
  675. nType==qsys::ViewEvent::VWE_PROPCHG_DRG) {
  676. setCenter(c);
  677. setDefaultPropFlag("center", false);
  678. }
  679. return;
  680. }
  681. if (m_bAutoUpdate) {
  682. if (nType==qsys::ViewEvent::VWE_PROPCHG) {
  683. setCenter(c);
  684. setDefaultPropFlag("center", false);
  685. }
  686. return;
  687. }
  688. return;
  689. }
  690. ///////////////////////////////////////////////////
  691. // Mol boundary mode routines
  692. void MapMeshRenderer::setBndryMolName(const LString &s)
  693. {
  694. if (s.equals(m_strBndryMol))
  695. return;
  696. m_strBndryMol = s;
  697. /// target mol is changed-->redraw map
  698. super_t::invalidateDisplayCache();
  699. }
  700. void MapMeshRenderer::setBndrySel(const SelectionPtr &pSel)
  701. {
  702. ensureNotNull(pSel);
  703. if (!m_pSelBndry.isnull())
  704. if (m_pSelBndry->equals(pSel.get()))
  705. return;
  706. m_pSelBndry = pSel;
  707. //setupMolBndry();
  708. /// selection is changed-->redraw map
  709. super_t::invalidateDisplayCache();
  710. }
  711. void MapMeshRenderer::setBndryRng(double d)
  712. {
  713. if (qlib::isNear4(d, m_dBndryRng))
  714. return;
  715. m_dBndryRng = d;
  716. if (m_dBndryRng<0.0)
  717. m_dBndryRng = 0.0;
  718. // setupMolBndry();
  719. if (m_bUseMolBndry)
  720. super_t::invalidateDisplayCache();
  721. }
  722. void MapMeshRenderer::setupMolBndry()
  723. {
  724. m_boundary.clear();
  725. m_bUseMolBndry = false;
  726. if (m_strBndryMol.isEmpty())
  727. return;
  728. qsys::ObjectPtr pobj = ensureNotNull(getScene())->getObjectByName(m_strBndryMol);
  729. MolCoordPtr pMol = MolCoordPtr(pobj, qlib::no_throw_tag());
  730. if (pMol.isnull()) {
  731. m_strBndryMol = LString();
  732. return;
  733. }
  734. AtomIterator aiter(pMol, m_pSelBndry);
  735. int i, natoms=0;
  736. for (aiter.first();
  737. aiter.hasMore();
  738. aiter.next()) {
  739. ++natoms;
  740. }
  741. m_boundary.alloc(natoms);
  742. for (aiter.first(), i=0;
  743. aiter.hasMore() && i<natoms ;
  744. aiter.next(), ++i) {
  745. m_boundary.setAt(i, aiter.get()->getPos(), aiter.getID());
  746. }
  747. m_boundary.build();
  748. m_bUseMolBndry = true;
  749. }
旧リポジトリブラウザで表示