00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
#ifndef SIMIONSL_PA_H
00043
#define SIMIONSL_PA_H
00044
00045
#include "util.h"
00046
00047
#include <iostream>
00048
#include <vector>
00049
#include <string>
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 namespace simion
00071 {
00072
00073
00074
00075
00076 enum symmetry_t
00077 {
00078
00079
CYLINDRICAL = 0,
00080
00081
PLANAR = 1
00082 };
00083
00084
00085
00086
00087 enum field_t
00088 {
00089
00090
ELECTROSTATIC = 0,
00091
00092
MAGNETIC = 1
00093 };
00094
00095
00096
00097
00098
00099 enum mirror_t
00100 {
00101
00102
MIRROR_X = 1,
00103
00104
MIRROR_Y = 2,
00105
00106
MIRROR_Z = 4,
00107
00108
MAGNETIC_PA = 8
00109 };
00110
00111
00112
class PA;
00113
class PAArgs;
00114
class PAHeader;
00115
class PAFormat;
00116
class PAPointInfo;
00117
class PATextHeader;
00118
class PATextHandler;
00119
class Vector3R;
00120
class Task;
00121
class PATextImpl_;
00122
00123
00124
00125
00126
00127 class Vector3R
00128 {
00129
public:
00130
00131
Vector3R(
double x=0.0,
double y=0.0,
double z=0.0);
00132
00133
00134
void set(
double x,
double y,
double z);
00135
00136
00137
double x()
const;
00138
00139
void x(
double val);
00140
00141
00142
double y()
const;
00143
00144
void y(
double val);
00145
00146
00147
double z()
const;
00148
00149
void z(
double val);
00150
00151
private:
00152
double x_, y_, z_;
00153 };
00154
00155
00156
00157
00158
00159
00160 class PAPoint
00161 {
00162
public:
00163
00164 bool electrode;
00165
00166 double potential;
00167
00168
00169
00170
00171
00172
00173 PAPoint(
bool electrode_,
double potential_) :
00174
electrode(electrode_),
potential(potential_) { }
00175
00176 };
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219 class PAArgs
00220 {
00221
public:
00222
00223 enum arg_t {
00224 A_file = (1 << 0),
00225 A_mode = (1 << 1),
00226 A_max_voltage = (1 << 2),
00227 A_nx = (1 << 3),
00228 A_ny = (1 << 4),
00229 A_nz = (1 << 5),
00230 A_mirror_x = (1 << 6),
00231 A_mirror_y = (1 << 7),
00232 A_mirror_z = (1 << 8),
00233 A_field_type = (1 << 9),
00234 A_symmetry = (1 << 10),
00235 A_ng = (1 << 11),
00236 A_fast_adjustable = (1 << 12),
00237 A_enable_points = (1 << 13)
00238 };
00239
00240
00241
00242
00243
PAArgs() :
00244 file_ (),
00245 mode_ (-1),
00246 max_voltage_ (100000),
00247 nx_ (100),
00248 ny_ (100),
00249 nz_ (1),
00250 mirror_x_ (false),
00251 mirror_y_ (false),
00252 mirror_z_ (false),
00253 field_type_ (
ELECTROSTATIC),
00254 symmetry_ (
PLANAR),
00255 ng_ (100),
00256 fast_adjustable_ (false),
00257 enable_points_ (true),
00258 valid_ (0)
00259 { }
00260
00261
00262
00263
00264
# ifndef DOXYGEN_SHOULD_SKIP_THIS
00265
# define SL_MAKE_METHODS(name, type) \
00266
\
00267 type name() const { return name ## _; } \
00268 \
00269 bool name ## _defined() const { return is_set_(A_ ## name); } \
00270 \
00271 PAArgs& name(type val) { name ## _ = val; set_(A_ ## name); return *this; }
00272
# endif
00273
00274 SL_MAKE_METHODS(file, std::string)
00275 SL_MAKE_METHODS(mode,
int)
00276 SL_MAKE_METHODS(max_voltage,
double)
00277 SL_MAKE_METHODS(nx,
int)
00278 SL_MAKE_METHODS(ny,
int)
00279 SL_MAKE_METHODS(nz,
int)
00280 SL_MAKE_METHODS(mirror_x,
bool)
00281 SL_MAKE_METHODS(mirror_y,
bool)
00282 SL_MAKE_METHODS(mirror_z,
bool)
00283 SL_MAKE_METHODS(field_type, field_t)
00284 SL_MAKE_METHODS(symmetry, symmetry_t)
00285 SL_MAKE_METHODS(ng,
int)
00286 SL_MAKE_METHODS(fast_adjustable,
bool)
00287 SL_MAKE_METHODS(enable_points,
bool)
00288
00289
00290
int defined();
00291
00292 # undef SL_MAKE_METHODS
00293
00294 private:
00295
00296 std::string file_;
00297
int mode_;
00298
double max_voltage_;
00299
int nx_;
00300
int ny_;
00301
int nz_;
00302
bool mirror_x_;
00303
bool mirror_y_;
00304
bool mirror_z_;
00305 field_t field_type_;
00306 symmetry_t symmetry_;
00307
int ng_;
00308
bool fast_adjustable_;
00309
bool enable_points_;
00310
00311
int valid_;
00312
00313
void set_(arg_t val);
00314
bool is_set_(arg_t val) const;
00315 };
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332 class
PAHeader
00333 {
00334
public:
00335
00336 int mode_;
00337
00338
00339 int symmetry_;
00340
00341
00342 double max_voltage_;
00343
00344
00345 int nx_;
00346
00347
00348 int ny_;
00349
00350
00351 int nz_;
00352
00353
00354
00355
00356
00357
00358 int mirror_;
00359
00360
00361
00362
00363 PAHeader() :
00364 mode_ (-1),
00365 symmetry_ (
PLANAR),
00366 max_voltage_ (100000.0),
00367 nx_ (100),
00368 ny_ (100),
00369 nz_ (1),
00370 mirror_ (0 + (100<<4))
00371 { }
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387 PAHeader(
00388
int mode,
00389 field_t field_type,
00390 symmetry_t symmetry,
00391
double max_voltage,
00392
int nx,
00393
int ny,
00394
int nz,
00395
bool mirror_x,
00396
bool mirror_y,
00397
bool mirror_z,
00398
int ng
00399 );
00400
00401
00402
bool mirror_x() const;
00403
00404
bool mirror_y() const;
00405
00406
bool mirror_z() const;
00407
00408
00409 field_t field_type() const;
00410
00411
00412
int ng() const;
00413
00414
00415 symmetry_t symmetry() const;
00416 };
00417
00418
00419
00420
00421 class
PATextHeader : public
PAArgs
00422 {
00423
public:
00424
00425 enum point_column_t
00426 {
00427 PI_X = (1<<0),
00428 PI_Y = (1<<1),
00429 PI_Z = (1<<2),
00430 PI_IS_ELECTRODE = (1<<3),
00431 PI_POTENTIAL = (1<<4),
00432 PI_RAW_VALUE = (1<<5),
00433 PI_FIELD_X = (1<<6),
00434 PI_FIELD_Y = (1<<7),
00435 PI_FIELD_Z = (1<<8),
00436
00437 PI_FIELD = PI_FIELD_X | PI_FIELD_Y | PI_FIELD_Z,
00438 PI_XYZ = PI_X | PI_Y | PI_Z
00439 };
00440
00441
00442
00443
00444 PATextHeader() : columns_enabled_(0) { }
00445
00446
00447
00448
00449
bool is_column_enabled(point_column_t t)
const;
00450
00451
00452
00453
00454
void enable_column(
int idx, point_column_t t);
00455
00456
00457
00458
00459
int enabled_columns() const;
00460
00461
00462
00463
00464 point_column_t column(
int idx) const;
00465
00466
00467
00468
00469
int column_count() const;
00470
00471 private:
00472
int columns_enabled_;
00473 std::vector<point_column_t> columns_;
00474 };
00475
00476
00477
00478
00479
00480
00481 class
PAFormat
00482 {
00483
public:
00484
00485 enum format_t {
00486
00487 BINARY,
00488
00489 ASCII
00490 };
00491
00492
00493 enum values_t {
00494
00495 POTENTIAL,
00496
00497 FIELD
00498 };
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511 PAFormat(
00512 format_t format = BINARY,
00513
double dx = 1,
00514
bool enable_header =
true,
00515
bool enable_data =
true,
00516
bool enable_coords =
true,
00517 values_t values = POTENTIAL)
00518 :
00519 format_ (format),
00520 dx_ (dx),
00521 enable_header_ (enable_header),
00522 enable_data_ (enable_data),
00523 enable_coords_ (enable_coords),
00524 values_ (values)
00525 { }
00526
00527
# ifndef DOXYGEN_SHOULD_SKIP_THIS
00528
# define SL_MAKE_METHODS(name, type) \
00529
\
00530 type name() const { return name ## _; } \
00531 \
00532 PAFormat& name(type val) { name ## _ = val; return *this;}
00533
# endif
00534
00535 SL_MAKE_METHODS(format, format_t)
00536 SL_MAKE_METHODS(dx,
double)
00537 SL_MAKE_METHODS(enable_header,
bool)
00538 SL_MAKE_METHODS(enable_data,
bool)
00539 SL_MAKE_METHODS(enable_coords,
bool)
00540 SL_MAKE_METHODS(values, values_t)
00541
00542 # undef SL_MAKE_METHODS
00543
00544 private:
00545 format_t format_;
00546
double dx_;
00547
bool enable_header_;
00548
bool enable_data_;
00549
bool enable_coords_;
00550 values_t values_;
00551 };
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561 class
PAPointInfo
00562 {
00563
private:
00564
int x_;
00565
int y_;
00566
int z_;
00567
bool is_electrode_;
00568
double potential_;
00569
double raw_value_;
00570
double field_x_;
00571
double field_y_;
00572
double field_z_;
00573
00574
int enabled_;
00575
public:
00576 PAPointInfo() :
00577 x_ (0),
00578 y_ (0),
00579 z_ (0),
00580 is_electrode_ (
false),
00581 potential_ (0.0),
00582 raw_value_ (0.0),
00583 field_x_ (0.0),
00584 field_y_ (0.0),
00585 field_z_ (0.0),
00586 enabled_ (0)
00587 { }
00588
00589
# ifndef DOXYGEN_SHOULD_SKIP_THIS
00590
# define SL_MAKE_METHODS(name, type) \
00591
\
00592 type name() const { return name ## _; } \
00593 \
00594 void name(type val) { name ## _ = val; }
00595
# endif
00596
00597 SL_MAKE_METHODS(x,
int)
00598 SL_MAKE_METHODS(y,
int)
00599 SL_MAKE_METHODS(z,
int)
00600 SL_MAKE_METHODS(is_electrode,
bool)
00601 SL_MAKE_METHODS(potential,
double)
00602 SL_MAKE_METHODS(raw_value,
double)
00603 SL_MAKE_METHODS(field_x,
double)
00604 SL_MAKE_METHODS(field_y,
double)
00605 SL_MAKE_METHODS(field_z,
double)
00606 SL_MAKE_METHODS(enabled,
int)
00607
00608 # undef SL_MAKE_METHODS
00609
00610
00611
00612
00613 std::string string()
const;
00614 };
00615
00616
00617
00618
00619
00620
00621
00622
00623 class PATextHandler
00624 {
00625
public:
00626
00627
00628
00629
00630
virtual void process_header(
const PATextHeader& header) = 0;
00631
00632
00633
00634
00635
00636
virtual void process_point(
const PAPointInfo& info) = 0;
00637 };
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718 class PA
00719 {
00720
public:
00721
enum {MAX_POINTS = 50000000};
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
PA();
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
PA(
const PAArgs& args);
00758
00759
00760
00761
00762
00763
virtual ~
PA();
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793 std::string header_string()
const;
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
void set_status(Task* status);
00805
00806
00807
00808
00809
00810
00811
00812
void load(
const std::string& path)
throw(std::string);
00813
00814
00815
00816
00817
00818
00819
00820
void load(std::istream& is)
throw(std::string);
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
void save(
const std::string& path,
const PAFormat& opt = PAFormat())
00845
throw(std::string);
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
void save(std::ostream& os,
const PAFormat& opt = PAFormat())
00856
throw(std::string);
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
bool enable_points()
const;
00876
00877
00878
00879
00880
void enable_points(
bool val);
00881
00882
00883
00884
00885
bool fast_adjustable()
const;
00886
00887
00888
00889
00890
void fast_adjustable(
bool val);
00891
00892
00893
00894
00895
00896
00897
field_t field_type()
const;
00898
00899
00900
00901
00902
00903
00904
void field_type(
field_t val);
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
double max_voltage()
const;
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
void max_voltage(
double val);
00928
00929
00930
00931
00932
00933
00934
bool mirror_x()
const;
00935
00936
00937
00938
00939
00940
00941
void mirror_x(
bool val);
00942
00943
00944
00945
00946
00947
00948
bool mirror_y()
const;
00949
00950
00951
00952
00953
00954
00955
00956
void mirror_y(
bool val);
00957
00958
00959
00960
00961
00962
00963
00964
bool mirror_z()
const;
00965
00966
00967
00968
00969
00970
00971
void mirror_z(
bool val);
00972
00973
00974
00975
00976
00977
00978
00979
00980
int mode()
const;
00981
00982
00983
00984
00985
00986
00987
void mode(
int val);
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
int ng()
const;
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
void ng(
int val);
01010
01011
01012
01013
01014
01015
01016
01017
int num_points()
const;
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
int num_voxels()
const;
01028
01029
01030
01031
01032
01033
01034
int nx()
const;
01035
01036
01037
01038
01039
01040
void nx(
int val);
01041
01042
01043
01044
01045
01046
01047
int ny()
const;
01048
01049
01050
01051
01052
01053
void ny(
int val);
01054
01055
01056
01057
01058
01059
01060
int nz()
const;
01061
01062
01063
01064
01065
01066
void nz(
int val);
01067
01068
01069
01070
01071
01072
PA* pasharp()
const;
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
void pasharp(
PA* pasharp);
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
void set(
const PAArgs& args);
01106
01107
01108
01109
01110
01111
void size(
int nx,
int ny,
int nz = 1);
01112
01113
01114
01115
01116
01117
01118
01119
symmetry_t symmetry()
const;
01120
01121
01122
01123
01124
01125
01126
void symmetry(
symmetry_t val);
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144
01145
bool inside(
int xi,
int yi,
int zi = 0)
const;
01146
01147
01148
01149
01150
01151
01152
01153
01154
01155
01156
01157
bool inside(
double x,
double y,
double z = 0.0)
const;
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
Vector3R norm_grid_coords(
double x,
double y,
double z)
const;
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
bool voxel_inside(
int xi,
int yi,
int zi = 0)
const;
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197
01198
01199
01200
void clear_points();
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
bool electrode(
int xi,
int yi,
int zi = 0)
const;
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
bool electrode(
double x,
double y,
double z = 0.0)
const;
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
void electrode(
int xi,
int yi,
int zi,
bool is_electrode);
01236
01237
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247
01248
Vector3R field(
double x,
double y,
double z = 0.0)
const;
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
void field(
int xi,
int yi,
int zi,
double ex,
double ey,
double ez,
01276
bool is_electrode =
false);
01277
01278
01279
01280
01281
PAPoint point(
int xi,
int yi,
int zi)
const;
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291
01292
void point(
int xi,
int yi,
int zi,
bool electrode,
double potential);
01293
01294
01295
01296
01297
01298
01299
01300
01301
01302
01303
01304
01305
double potential(
int xi,
int yi,
int zi = 0)
const;
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318
double potential(
double x,
double y,
double z = 0.0)
const;
01319
01320
01321
01322
01323
01324
01325
01326
01327
01328
01329
void potential(
int xi,
int yi,
int zi,
double potential);
01330
01331
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345
double raw_value(
int xi,
int yi,
int zi = 0)
const;
01346
01347
01348
01349
01350
01351
01352
01353
01354
01355
01356
01357
01358
01359
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369
01370
void raw_value(
int xi,
int yi,
int zi,
double val);
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380
01381
01382
01383
01384
01385
01386
01387
01388
void solid(
int xi,
int yi,
int zi,
bool is_electrode,
double potential);
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403
bool solid(
int xi,
int yi,
int zi = 0)
const;
01404
01405
01406
01407
01408
01409
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
void parse_ascii(std::istream& is,
PATextHandler& handler);
01424
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434
01435
01436
01437
01438
01439
01440
01441
bool check(
const PAArgs& args);
01442
01443
01444
01445
01446
01447
01448
bool check_field_type(
field_t val);
01449
01450
01451
01452
01453
01454
bool check_mode(
int val);
01455
01456
01457
01458
01459
01460
bool check_max_voltage(
double val);
01461
01462
01463
01464
01465
01466
bool check_ng(
int val);
01467
01468
01469
01470
01471
01472
bool check_nx(
int val);
01473
01474
01475
01476
01477
01478
bool check_ny(
int val);
01479
01480
01481
01482
01483
01484
bool check_nz(
int val);
01485
01486
01487
01488
01489
01490
01491
01492
01493
01494
01495
bool check_size(
int nx,
int ny,
int nz = 1);
01496
01497
01498
01499
01500
01501
01502
bool check_symmetry(
symmetry_t val);
01503
01504
01505
01506
01507
inline std::string error()
const;
01508
01509
01510
01511
01512
01513
01514
01515
01516
01517
static std::string symmetry_string(
symmetry_t val);
01518
01519
01520
01521
01522
01523
01524
01525
static std::string field_string(
field_t val);
01526
01527
private:
01528
int mode_;
01529
field_t field_type_;
01530
symmetry_t symmetry_;
01531
bool mirror_x_;
01532
bool mirror_y_;
01533
bool mirror_z_;
01534
int nx_;
01535
int ny_;
01536
int nz_;
01537
bool fast_adjustable_;
01538
double max_voltage_;
01539
int ng_;
01540
bool enable_points_;
01541
01542
double* points_;
01543
01544 PATextImpl_* pat_;
01545
PA* pasharp_;
01546
01547
01548 std::string error_;
01549
01550
01551 std::string fail_point_(
int x,
int y,
int z)
const;
01552 std::string fail_point_(
double x,
double y,
double z)
const;
01553
01554
int pos_(
int xi,
int yi,
int zi)
const;
01555
01556
01557
01558
01559
01560
01561
01562
void create_points_();
01563
01564
01565
01566
01567
01568
01569
01570
01571
void destroy_points_();
01572
01573
01574
01575
01576
01577
01578
01579
01580
01581
01582
01583
bool inside_cylindrical_(
double x,
double r)
const;
01584
01585
void load_ascii_(std::istream& is)
throw(std::string);
01586
void load_binary_(std::istream& is)
throw(std::string);
01587
01588
void save_ascii_(std::ostream& os,
const PAFormat& opt)
throw(std::string);
01589
void save_binary_(std::ostream& os,
const PAFormat& opt)
throw(std::string);
01590
01591
01592
bool fail_string_(
const std::string& str);
01593
bool fail_mode_(
int val);
01594
bool fail_max_voltage_(
double val);
01595
bool fail_nx1_(
int val);
01596
bool fail_nx2_(
int val);
01597
bool fail_ny1_(
int val);
01598
bool fail_ny2_(
int val);
01599
bool fail_nz1_(
int val);
01600
bool fail_nz2_(
int val);
01601
bool fail_ng_(
int val);
01602
bool fail_field_type_(
field_t val);
01603
bool fail_symmetry_(
symmetry_t val);
01604
bool fail_size_(
int nx,
int ny,
int nz);
01605 };
01606
01607
01608
01609
01610
01611
01612
01613
#ifndef DOXYGEN_SHOULD_SKIP_THIS
01614
#define SL_MAKE_ARGS \
01615
(PAArgs().nx(nx_).ny(ny_).nz(nz_).symmetry(symmetry_). \
01616
mirror_x(mirror_x_).mirror_y(mirror_y_).mirror_z(mirror_z_))
01617
#endif
01618
01619
01620
01621
01622 inline PAHeader::PAHeader(
01623
int mode,
01624 field_t field_type,
01625 symmetry_t symmetry,
01626
double max_voltage,
01627
int nx,
01628
int ny,
01629
int nz,
01630
bool mirror_x,
01631
bool mirror_y,
01632
bool mirror_z,
01633
int ng
01634 ) :
01635 mode_ (mode),
01636 symmetry_ (symmetry != 0 ? 1 : 0),
01637 max_voltage_ (max_voltage),
01638 nx_ (nx),
01639 ny_ (ny),
01640 nz_ (nz),
01641 mirror_ ( (mirror_x ?
MIRROR_X : 0) |
01642 (mirror_y ?
MIRROR_Y : 0) |
01643 (mirror_z ?
MIRROR_Z : 0) |
01644 (field_type ==
MAGNETIC ?
MAGNETIC_PA : 0) |
01645 (ng << 4)
01646 )
01647 {
01648 }
01649
01650 inline field_t PAHeader::field_type()
const
01651
{
01652
return (mirror_ &
MAGNETIC_PA) != 0 ?
MAGNETIC :
ELECTROSTATIC;
01653 }
01654 inline bool PAHeader::mirror_x()
const {
return (mirror_ &
MIRROR_X) != 0; }
01655 inline bool PAHeader::mirror_y()
const {
return (mirror_ &
MIRROR_Y) != 0; }
01656 inline bool PAHeader::mirror_z()
const {
return (mirror_ &
MIRROR_Z) != 0; }
01657 inline int PAHeader::ng()
const {
return mirror_ >> 4; }
01658 inline symmetry_t PAHeader::symmetry()
const {
01659
return symmetry_ ==
PLANAR ?
PLANAR :
CYLINDRICAL;
01660 }
01661
01662
01663
01664 inline void PATextHeader::enable_column(
int idx, point_column_t t)
01665 {
01666
if(idx >= (
int)columns_.size())
01667 columns_.resize(idx+1);
01668
if(idx != -1) {
01669 columns_enabled_ |= t;
01670 columns_[idx] = t;
01671 }
01672
else {
01673 columns_enabled_ &= ~t;
01674 columns_[idx] = (
point_column_t)0;
01675 }
01676 }
01677 inline PATextHeader::point_column_t PATextHeader::column(
int idx)
const
01678
{
return columns_[idx]; }
01679 inline int PATextHeader::column_count()
const {
return columns_.size(); }
01680 inline int PATextHeader::enabled_columns()
const {
return columns_enabled_; }
01681 inline bool PATextHeader::is_column_enabled(point_column_t t)
const
01682
{
01683
return (columns_enabled_ & t) != 0;
01684 }
01685
01686
01687
01688
01689
01690 inline int PAArgs::defined() {
return valid_; }
01691
inline bool PAArgs::is_set_(PAArgs::arg_t val)
const {
return (valid_ & val) != 0; }
01692
inline void PAArgs::set_(PAArgs::arg_t val) { valid_ |= val; }
01693
01694
01695
01696 inline Vector3R::Vector3R(
double x,
double y,
double z) :
01697 x_(x), y_(y), z_(z)
01698 { }
01699 inline void Vector3R::set(
double x,
double y,
double z)
01700 { x_ = x; y_ = y; z_ = z; }
01701 inline double Vector3R::x()
const {
return x_; }
01702 inline void Vector3R::x(
double val) { x_ = val; }
01703 inline double Vector3R::y()
const {
return y_; }
01704 inline void Vector3R::y(
double val) { y_ = val; }
01705 inline double Vector3R::z()
const {
return z_; }
01706 inline void Vector3R::z(
double val) { z_ = val; }
01707
01708
01709
01710
inline std::string PA::fail_point_(
double x,
double y,
double z)
const
01711
{
01712
return (std::string)
"point (" + str(x) +
"," + str(y) +
"," + str(z) +
01713
") out of bounds (" + str(nx_) +
"," + str(ny_) +
"," + str(nz_) +
").";
01714 }
01715
01716
inline std::string PA::fail_point_(
int xi,
int yi,
int zi)
const
01717
{
01718
return (std::string)
"point (" + str(xi) +
"," + str(yi) +
"," + str(zi) +
01719
") out of bounds (" + str(nx_) +
"," + str(ny_) +
"," + str(nz_) +
").";
01720 }
01721
01722
inline int PA::pos_(
int xi,
int yi,
int zi)
const
01723
{
01724
return (zi * ny_ + yi) * nx_ + xi;
01725 }
01726
01727
01728 inline bool PA::enable_points()
const {
return enable_points_; }
01729 inline void PA::enable_points(
bool val) {
01730
if(val && !enable_points_) destroy_points_();
01731
if(!val && enable_points_) create_points_();
01732 enable_points_ = val;
01733
01734 }
01735
01736 inline bool PA::fast_adjustable()
const {
return fast_adjustable_; }
01737 inline void PA::fast_adjustable(
bool val) { fast_adjustable_ = val; }
01738
01739 inline field_t PA::field_type()
const {
return field_type_; }
01740 inline void PA::field_type(field_t val)
01741 {
01742 field_type_ = val;
01743 }
01744
01745 inline double PA::max_voltage()
const {
return max_voltage_; }
01746 inline void PA::max_voltage(
double val)
01747 {
01748 sl_assert(
check_max_voltage(val),
"max_voltage",
error());
01749 max_voltage_ = val;
01750 }
01751
01752 inline bool PA::mirror_x()
const {
return mirror_x_; }
01753 inline void PA::mirror_x(
bool val)
01754 {
01755 mirror_x_ = !!val;
01756 }
01757
01758 inline bool PA::mirror_y()
const {
return mirror_y_; }
01759 inline void PA::mirror_y(
bool val)
01760 {
01761 sl_assert(
check(SL_MAKE_ARGS.mirror_y(val)),
"mirror_y",
error());
01762 mirror_y_ = !!val;
01763 }
01764
01765 inline bool PA::mirror_z()
const {
return mirror_z_; }
01766 inline void PA::mirror_z(
bool val)
01767 {
01768 sl_assert(
check(SL_MAKE_ARGS.mirror_z(val)),
"mirror_z",
error());
01769
01770 mirror_z_ = !!val;
01771 }
01772
01773 inline int PA::mode()
const {
return mode_; }
01774 inline void PA::mode(
int val)
01775 {
01776 sl_assert(
check_mode(val),
"mode",
error());
01777 mode_ = val;
01778 }
01779
01780 inline int PA::ng()
const {
return ng_; }
01781 inline void PA::ng(
int val)
01782 {
01783
01784 sl_assert(
check_ng(val),
"ng",
error());
01785 ng_ = val;
01786 }
01787
01788 inline int PA::num_points()
const {
return nx_ * ny_ * nz_; }
01789
01790 inline int PA::num_voxels()
const {
01791
int num = (nx_ - 1) * (ny_ - 1);
01792
if(nz_ != 1) num *= (nz_ - 1);
01793
return num;
01794 }
01795
01796 inline int PA::nx()
const {
return nx_; }
01797 inline void PA::nx(
int val)
01798 {
01799 sl_assert(
check_nx(val),
"nx",
error());
01800 nx_ = val;
01801 }
01802
01803 inline int PA::ny()
const {
return ny_; }
01804 inline void PA::ny(
int val)
01805 {
01806 sl_assert(
check_ny(val),
"ny",
error());
01807 ny_ = val;
01808 }
01809
01810 inline int PA::nz()
const {
return nz_; }
01811 inline void PA::nz(
int val)
01812 {
01813 sl_assert(
check_nz(val),
"nz",
error());
01814 nz_ = val;
01815 }
01816
01817 inline PA* PA::pasharp()
const {
return pasharp_; }
01818 inline void PA::pasharp(
PA* pasharp) { pasharp_ = pasharp; }
01819
01820 inline symmetry_t PA::symmetry()
const {
return (
symmetry_t)symmetry_; }
01821 inline void PA::symmetry(symmetry_t val)
01822 {
01823 symmetry_ = (val ==
CYLINDRICAL) ?
CYLINDRICAL :
PLANAR;
01824 }
01825
01826
01827 inline bool PA::electrode(
int xi,
int yi,
int zi)
const
01828
{
01829 sl_assert(
inside(xi, yi, zi),
"electrode", fail_point_(xi,yi,zi));
01830
01831
return raw_value(xi, yi, zi) >
max_voltage();
01832 }
01833
01834 inline void PA::electrode(
int xi,
int yi,
int zi,
bool is_electrode)
01835 {
01836 sl_assert(
inside(xi, yi, zi),
"point", fail_point_(xi, yi, zi));
01837
01838
int pos = pos_(xi,yi,zi);
01839
if(points_[pos] > max_voltage_) {
01840
if(!is_electrode) points_[pos] -= 2 * max_voltage_;
01841 }
01842
else {
01843
if(!is_electrode) points_[pos] += 2 * max_voltage_;
01844 }
01845 }
01846
01847 inline PAPoint PA::point(
int xi,
int yi,
int zi)
const
01848
{
01849
return PAPoint(
electrode(xi,yi,zi),
potential(xi,yi,zi));
01850 }
01851
01852 inline void PA::point(
int xi,
int yi,
int zi,
bool electrode,
double potential)
01853 {
01854 sl_assert(
inside(xi, yi, zi),
"point", fail_point_(xi, yi, zi));
01855 sl_assert(potential <=
max_voltage(),
"point",
01856 (std::string)
"Potential (" + str(potential) +
") exceeds max voltage ("
01857 + str(
max_voltage()) +
")");
01858
01859
double val = electrode ? 2*
max_voltage() + potential
01860 : potential;
01861
raw_value(xi, yi, zi, val);
01862 }
01863
01864 inline double PA::potential(
int xi,
int yi,
int zi)
const
01865
{
01866 sl_assert(
inside(xi, yi, zi),
"potential", fail_point_(xi, yi, zi));
01867
01868
double val =
raw_value(xi, yi, zi);
01869
if(val >
max_voltage())
01870 val -= 2*
max_voltage();
01871
01872
01873
01874
return val;
01875 }
01876
01877 inline void PA::potential(
int xi,
int yi,
int zi,
double potential)
01878 {
01879 sl_assert(
inside(xi, yi, zi),
"potential", fail_point_(xi, yi, zi));
01880 sl_assert(potential <=
max_voltage(),
"point",
01881 (std::string)
"Potential (" + str(potential) +
")" +
01882
" exceeds max voltage (" + str(
max_voltage()) +
")");
01883
01884
int pos = pos_(xi,yi,zi);
01885
bool is_electrode = (points_[pos] > max_voltage_);
01886 points_[pos] = potential;
01887
if(is_electrode) points_[pos] += 2 * max_voltage_;
01888 }
01889
01890 inline double PA::raw_value(
int xi,
int yi,
int zi)
const
01891
{
01892 sl_assert(
inside(xi, yi, zi),
"raw_value", fail_point_(xi,yi,zi));
01893
01894
return points_[pos_(xi,yi,zi)];
01895 }
01896 inline void PA::raw_value(
int xi,
int yi,
int zi,
double val)
01897 {
01898 sl_assert(
inside(xi, yi, zi),
"raw_value", fail_point_(xi, yi, zi));
01899
01900 points_[pos_(xi,yi,zi)] = val;
01901 }
01902
01903
01904 inline bool PA::check_mode(
int val)
01905 {
01906
if(val != -1)
return fail_mode_(val);
01907
return true;
01908 }
01909
01910 inline bool PA::check_max_voltage(
double val)
01911 {
01912
if(val <= 0)
return fail_max_voltage_(val);
01913
return true;
01914 }
01915
01916 inline bool PA::check_nx(
int val)
01917 {
01918
if(val < 3)
return fail_nx1_(val);
01919
if(val > 90000)
return fail_nx1_(val);
01920
return true;
01921 }
01922
01923 inline bool PA::check_ny(
int val)
01924 {
01925
if(val < 3)
return fail_ny1_(val);
01926
if(val > 90000)
return fail_ny2_(val);
01927
return true;
01928 }
01929
01930 inline bool PA::check_nz(
int val)
01931 {
01932
if(val < 1)
return fail_nz1_(val);
01933
if(val > 90000)
return fail_nz2_(val);
01934
return true;
01935 }
01936
01937 inline bool PA::check_ng(
int val)
01938 {
01939
if(val < 0)
return fail_ng_(val);
01940
return true;
01941 }
01942
01943 inline bool PA::check_field_type(field_t val)
01944 {
01945
if(val !=
ELECTROSTATIC && val !=
MAGNETIC)
01946
return fail_field_type_(val);
01947
return true;
01948 }
01949
01950 inline bool PA::check_symmetry(symmetry_t val)
01951 {
01952
if(val !=
PLANAR && val !=
CYLINDRICAL)
01953
return fail_symmetry_(val);
01954
return true;
01955 }
01956 inline bool PA::check_size(
int nx,
int ny,
int nz)
01957 {
01958
if(!(
check_nx(nx) &&
check_ny(ny) &&
check_nz(nz)))
return false;
01959
if(mult_overflow(nx,ny) || mult_overflow(nx*ny,nz) || nx*ny*nz > 50000000)
01960
return fail_size_(nx, ny, nz);
01961
return true;
01962 }
01963
01964 inline std::string PA::error()
const {
return error_; }
01965
01966
#undef SL_MAKE_ARGS
01967
01968 }
01969
01970
#endif // first include
01971