SRMeasures.txt 142 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Threading;
  6. using System.Windows;
  7. using System.Windows.Threading;
  8. using UtilityService;
  9. using Vinno.DataManager.Data;
  10. using Vinno.DataManager.Infrastructure;
  11. using Vinno.DataManager.Infrastructure.Interfaces;
  12. using Vinno.DataManager.Utilities;
  13. using Vinno.DataTypes;
  14. using Vinno.Enums;
  15. using Vinno.Infrastructure;
  16. using Vinno.Infrastructure.Enums;
  17. using Vinno.Infrastructure.Interfaces;
  18. using Vinno.Infrastructure.Utilities;
  19. using Vinno.Models.Base;
  20. using Vinno.Models.Base.Modes;
  21. using Vinno.Models.Base.Parameters;
  22. using Vinno.Models.Base.VisualAreas;
  23. using Vinno.Models.Base.Visuals;
  24. using Vinno.Models.Dicom.Replay.Modes;
  25. using Vinno.Models.SpecificImpl.Modes;
  26. using Vinno.Modules.MeasureModule.Calculators;
  27. using Vinno.Modules.MeasureModule.ItemMetas;
  28. using Vinno.Modules.MeasureModule.Items;
  29. using Vinno.Modules.MeasureModule.Results;
  30. using Vinno.Modules.RenderModule;
  31. using Vinno.Services.InputServices;
  32. using Vinno.Services.MessageService;
  33. using Vinno.Utilities;
  34. using Vinno.vCloud.Report.JsonConverters;
  35. namespace Vinno.Modules.MeasureModule.Primitives.SRMeasure
  36. {
  37. public static class SRPointTrans
  38. {
  39. //Scream Point To ImgPoint
  40. public static DPoint TransPointS2I(DPoint srcPoint, double roundw, double roundh, double urmw, double urmh, int datew, int dateh, bool limit = true)
  41. {
  42. double Scalarx = (double) datew / urmw;
  43. double Scalary = (double) dateh / urmh;
  44. DPoint urmzeroPoint=new DPoint(-urmw/2,(roundh- urmh) /2);
  45. DPoint outPoint = new DPoint((srcPoint.X - urmzeroPoint.X) * Scalarx,
  46. (srcPoint.Y - urmzeroPoint.Y) * Scalary);
  47. if (limit)
  48. {
  49. if (outPoint.X < 0)
  50. outPoint.X = 0;
  51. if (outPoint.X > (datew - 1))
  52. outPoint.X = datew - 1;
  53. if (outPoint.Y < 0)
  54. outPoint.Y = 0;
  55. if (outPoint.Y > (dateh - 1))
  56. outPoint.Y = dateh - 1;
  57. }
  58. return outPoint;
  59. }
  60. //Scream Point To ImgPoint
  61. public static DPoint TransPointI2S(DPoint srcPoint, double roundw, double roundh, double urmw, double urmh, int datew, int dateh)
  62. {
  63. double Scalarx = (double)urmw/ datew;
  64. double Scalary = (double) urmh/ dateh ;
  65. DPoint urmzeroPoint = new DPoint(-urmw / 2, (roundh - urmh) / 2);
  66. DPoint outPoint = new DPoint(srcPoint.X * Scalarx+ urmzeroPoint.X, srcPoint.Y * Scalary + urmzeroPoint.Y);
  67. return outPoint;
  68. }
  69. }
  70. // 用于
  71. public class SRStraightCurvatureLineMeasure : StraightCurvatureLine
  72. {
  73. private bool calflag = false;
  74. public SRStraightCurvatureLineMeasure(ItemMeta meta, IMeasureItem parent):base(meta, parent)
  75. {
  76. }
  77. protected override bool OnExecute(PointInfo args)
  78. {
  79. if (args.VisualArea is ISRDicom)
  80. {
  81. var dicomvisual = args.VisualArea as ISRDicom;
  82. bool isSRDen = dicomvisual.isSRDen();
  83. if (args.VisualArea.Mode == null || !isSRDen)
  84. {
  85. return false;
  86. }
  87. }
  88. else
  89. {
  90. var modewithurm = args.VisualArea.Mode as IModeWithURM;
  91. if (modewithurm == null||modewithurm?.URMStyle!="URM(Den)")
  92. return false;
  93. }
  94. calflag = false;
  95. var preState = State;
  96. var result = base.OnExecute(args);
  97. if (result && preState == ItemStates.Running && State == ItemStates.Finished)
  98. {
  99. calflag = true;
  100. }
  101. return result;
  102. }
  103. protected override void OnExecuted(PointInfo args)
  104. {
  105. if (GeoFeature != null && Calculator != null&& calflag)
  106. {
  107. Calculator.Calculate();
  108. }
  109. }
  110. internal static StraightCurvatureLine CreateSRStraightCurvatureLineMeasure(ItemMeta meta, IMeasureItem parent)
  111. {
  112. if (meta == null || meta.BaseType != MeasureTypes.SRStraightCurvatureLineMeasure)
  113. {
  114. throw new ArgumentException();
  115. }
  116. var item = new SRStraightCurvatureLineMeasure(meta, parent);
  117. item.Calculator = new SRStraightCurvatureLineCal(item);
  118. return item;
  119. }
  120. internal class SRStraightCurvatureLineCal : Calculator<StraightCurvatureLine>
  121. {
  122. internal static readonly string SRkey = "SRCurvature";
  123. protected internal override string[] SupportedOutputKeys
  124. {
  125. get { return new[] { SRkey }; }
  126. }
  127. public SRStraightCurvatureLineCal(StraightCurvatureLine straightLine)
  128. : base(straightLine)
  129. {
  130. }
  131. public SRStraightCurvatureLineCal()
  132. {
  133. }
  134. protected override void OnCalculate()
  135. {
  136. var wizardManager = ServiceManager.Instance.GetService<IWizardManager>();
  137. wizardManager.Startup("URM", "Calculating...", CalculatSRCurvature, double.NaN, WizardButtonEnum.None);
  138. }
  139. private void CalculatSRCurvature()
  140. {
  141. TaskManagerFactory.Instance.GetTaskManager("Calculating")
  142. .StartNewTaskProxy("CalculatSRCurvature", CalculteSRCurvature, OnSRCurvatureCalculated);
  143. }
  144. private void CalculteSRCurvature(TaskProxy proxy)
  145. {
  146. StraightLineFeature feature = RefItem.GeoFeature;
  147. int width = 0;
  148. int height = 0;
  149. double UrmPhysicalwidth = 0;
  150. double UrmPhysicalheight = 0;
  151. NativeArray srcArray = new NativeArray(0);
  152. if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
  153. {
  154. var dicomvisual = feature.HostArea as ISRDicom;
  155. bool isSRDen = dicomvisual.isSRDen();
  156. if (!isSRDen)
  157. return;
  158. var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
  159. ref UrmPhysicalheight);
  160. //todo 坐标转换
  161. srcArray.Resize(dicomdate.Length);
  162. Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
  163. }
  164. else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
  165. {
  166. var modewithURM = feature.HostArea.Mode as IModeWithURM;
  167. if(modewithURM.URMStyle!="URM(Den)")
  168. return;
  169. var date = modewithURM.UrmArray;
  170. width = modewithURM.URMImgWidth;
  171. height = modewithURM.URMImgHeight;
  172. UrmPhysicalwidth = modewithURM.URMPhyWidth;
  173. UrmPhysicalheight = modewithURM.URMPhyHeight;
  174. srcArray.Resize(date.Length);
  175. Marshal.Copy(date, 0, srcArray.Start, date.Length);
  176. }
  177. else
  178. {
  179. return;
  180. }
  181. if (srcArray.Length != 8 * width * height)
  182. {
  183. _delayAction.BeginInvoke();
  184. return;
  185. }
  186. double regionwidth = feature.HostArea.ViewPort.Region.Width;
  187. double regionheight = feature.HostArea.ViewPort.Region.Height;
  188. DPoint startDPoint = SRPointTrans.TransPointS2I(feature.StartPoint, regionwidth, regionheight,
  189. UrmPhysicalwidth, UrmPhysicalheight, width, height);
  190. DPoint endDPoint = SRPointTrans.TransPointS2I(feature.EndPoint, regionwidth, regionheight,
  191. UrmPhysicalwidth, UrmPhysicalheight, width, height);
  192. if (startDPoint.X < 0 || startDPoint.X > width || endDPoint.X < 0 || endDPoint.X > width
  193. || startDPoint.Y < 0 || startDPoint.Y > height || endDPoint.Y < 0 || endDPoint.Y > height)
  194. return;
  195. int outPointsNum = 0;
  196. double curvature = 0;
  197. var urmcal = feature.HostArea.Mode as IURMCal;
  198. if(urmcal == null)
  199. return;
  200. double[] outPoints = urmcal.GetSRCurvature(srcArray.Start, width, height, startDPoint.X,
  201. startDPoint.Y, endDPoint.X, endDPoint.Y, ref curvature, ref outPointsNum);
  202. DPoint[] points = new DPoint[outPointsNum];
  203. for (int i = 0; i < outPointsNum; i++)
  204. {
  205. DPoint imgpoint = new DPoint(outPoints[i], outPoints[i + outPointsNum]);
  206. points[i] = SRPointTrans.TransPointI2S(imgpoint, regionwidth, regionheight,
  207. UrmPhysicalwidth, UrmPhysicalheight, width, height);
  208. }
  209. List<GeometryFeature> autoLines = new List<GeometryFeature>
  210. {
  211. new ManualTraceFeature(points, feature.Creator, feature.XUnit, feature.YUnit)
  212. };
  213. ServiceManager.MainDispatcher.Invoke(UpdateChildFeatures, autoLines);
  214. feature.UpdateValue(PrimaryOutput, RoundValue(curvature, GetResultDigits(PrimaryOutput)), Unit.None);
  215. }
  216. public void UpdateChildFeatures(List<GeometryFeature> autoLines)
  217. {
  218. var feature = RefItem.GeoFeature;
  219. if (feature != null)
  220. feature.UpdateChildFeatures(autoLines);
  221. }
  222. private void OnSRCurvatureCalculated(TaskProxy proxy)
  223. {
  224. IWizardManager manager = ServiceManager.Instance.GetService<IWizardManager>();
  225. using (manager.ClosingWizard())
  226. {
  227. var showError = false;
  228. if (proxy.Task.IsCanceled)
  229. {
  230. Logger.WriteLineInfo("Task:{0} is canceled.", proxy.Name);
  231. }
  232. else if (proxy.Task.Exception != null)
  233. {
  234. showError = true;
  235. Logger.WriteLineError("Task:{0} failed, exception: {1}.", proxy.Name, proxy.Task.Exception);
  236. }
  237. if (!showError || (bool)proxy.Tag)
  238. {
  239. manager.Close();
  240. }
  241. else
  242. {
  243. manager.Close("SRCurvatureCalculate failed", false);
  244. }
  245. }
  246. }
  247. }
  248. }
  249. public class SRCurveCurvatureLineMeasure : Trace
  250. {
  251. private bool calflag = false;
  252. public SRCurveCurvatureLineMeasure(ItemMeta meta, IMeasureItem parent) : base(meta, parent)
  253. {
  254. }
  255. protected override bool OnExecute(PointInfo args)
  256. {
  257. var cal = Calculator as SRCurveCurvatureLineCal;
  258. if (args.VisualArea is ISRDicom)
  259. {
  260. var dicomvisual = args.VisualArea as ISRDicom;
  261. bool isSRDen = dicomvisual.isSRDen();
  262. if (args.VisualArea.Mode == null || !isSRDen)
  263. {
  264. return false;
  265. }
  266. }
  267. else
  268. {
  269. var modewithurm = args.VisualArea.Mode as IModeWithURM;
  270. if (modewithurm == null || modewithurm?.URMStyle != "URM(Den)")
  271. return false;
  272. }
  273. calflag = false;
  274. cal.calflag = false;
  275. var preState = State;
  276. var result = base.OnExecute(args);
  277. if (result && preState == ItemStates.Running && State == ItemStates.Finished)
  278. {
  279. calflag = true;
  280. cal.calflag = true;
  281. }
  282. return result;
  283. }
  284. protected override void OnExecuted(PointInfo args)
  285. {
  286. if (GeoFeature != null && Calculator != null && calflag)
  287. {
  288. Calculator.Calculate();
  289. }
  290. }
  291. internal static Trace CreateSRCurveCurvatureLineMeasure(ItemMeta meta, IMeasureItem parent)
  292. {
  293. if (meta == null || meta.BaseType != MeasureTypes.SRCurveCurvatureLineMeasure)
  294. {
  295. throw new ArgumentException();
  296. }
  297. var item = new SRCurveCurvatureLineMeasure(meta, parent);
  298. item.Calculator = new SRCurveCurvatureLineCal(item);
  299. return item;
  300. }
  301. internal class SRCurveCurvatureLineCal : Calculator<Trace>
  302. {
  303. public bool calflag = false;
  304. internal static readonly string URMkey = "SRCurvature";
  305. protected internal override string[] SupportedOutputKeys
  306. {
  307. get { return new[] { URMkey }; }
  308. }
  309. public SRCurveCurvatureLineCal(Trace trace)
  310. : base(trace)
  311. {
  312. }
  313. public SRCurveCurvatureLineCal()
  314. {
  315. }
  316. protected override void OnCalculate()
  317. {
  318. if (!calflag)
  319. return;
  320. PolyLineFeature feature = RefItem.GeoFeature;
  321. int width = 0;
  322. int height = 0;
  323. double UrmPhysicalwidth = 0;
  324. double UrmPhysicalheight = 0;
  325. NativeArray srcArray = new NativeArray(0);
  326. if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
  327. {
  328. var dicomvisual = feature.HostArea as ISRDicom;
  329. bool isSRDen = dicomvisual.isSRDen();
  330. if (!isSRDen)
  331. return;
  332. var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
  333. ref UrmPhysicalheight);
  334. //todo 坐标转换
  335. srcArray.Resize(dicomdate.Length);
  336. Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
  337. }
  338. else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
  339. {
  340. var modewithURM = feature.HostArea.Mode as IModeWithURM;
  341. if (modewithURM.URMStyle != "URM(Den)")
  342. return;
  343. var date = modewithURM.UrmArray;
  344. width = modewithURM.URMImgWidth;
  345. height = modewithURM.URMImgHeight;
  346. UrmPhysicalwidth = modewithURM.URMPhyWidth;
  347. UrmPhysicalheight = modewithURM.URMPhyHeight;
  348. srcArray.Resize(date.Length);
  349. Marshal.Copy(date, 0, srcArray.Start, date.Length);
  350. }
  351. else
  352. {
  353. return;
  354. }
  355. if (srcArray.Length != 8 * width * height)
  356. {
  357. _delayAction.BeginInvoke();
  358. return;
  359. }
  360. double regionwidth = feature.HostArea.ViewPort.Region.Width;
  361. double regionheight = feature.HostArea.ViewPort.Region.Height;
  362. var SrcDPoints =new List<DPoint>();
  363. for (int i = 0; i < feature.Points.Count; i++)
  364. {
  365. var curpoint = SRPointTrans.TransPointS2I(feature.Points[i], regionwidth, regionheight,
  366. UrmPhysicalwidth, UrmPhysicalheight, width, height);
  367. SrcDPoints.Add(curpoint);
  368. }
  369. if (SrcDPoints[0].X < 0 || SrcDPoints[0].X > width || SrcDPoints.Last().X < 0 || SrcDPoints.Last().X > width
  370. || SrcDPoints[0].Y < 0 || SrcDPoints[0].Y > height || SrcDPoints.Last().Y < 0 || SrcDPoints.Last().Y > height)
  371. return;
  372. double curvature = 0;
  373. var urmcal = feature.HostArea.Mode as IURMCal;
  374. if (urmcal == null)
  375. return;
  376. urmcal.GetSRTraceCurvaturel(srcArray.Start, width, height, SrcDPoints, ref curvature);
  377. feature.UpdateValue(PrimaryOutput, RoundValue(curvature, GetResultDigits(PrimaryOutput)), Unit.None);
  378. }
  379. }
  380. }
  381. public class SRCurvatureMeasure : MultiMethodItem
  382. {
  383. internal SRCurvatureMeasure(ItemMeta meta, IMeasureItem parent = null) : base(meta, parent)
  384. {
  385. }
  386. internal static SRCurvatureMeasure CreateSRCurvatureMeasure(ItemMeta meta, IMeasureItem parent)
  387. {
  388. if (meta.BaseType != MeasureTypes.SRCurvature)
  389. {
  390. throw new ArgumentException();
  391. }
  392. var item = new SRCurvatureMeasure(meta, parent);
  393. return item;
  394. }
  395. }
  396. public class URMVesselMeasure : StraightLine
  397. {
  398. private bool calflag = false;
  399. public URMVesselMeasure(ItemMeta meta, IMeasureItem parent) : base(meta, parent)
  400. {
  401. }
  402. protected override bool OnExecute(PointInfo args)
  403. {
  404. if (args.VisualArea is ISRDicom)
  405. {
  406. var dicomvisual = args.VisualArea as ISRDicom;
  407. bool isSRDen = dicomvisual.isSRDen();
  408. if (args.VisualArea.Mode == null || !isSRDen)
  409. {
  410. return false;
  411. }
  412. }
  413. else
  414. {
  415. var modewithurm = args.VisualArea.Mode as IModeWithURM;
  416. if (modewithurm == null || modewithurm?.URMStyle != "URM(Den)")
  417. return false;
  418. }
  419. calflag = false;
  420. var preState = State;
  421. var result = base.OnExecute(args);
  422. if (result && preState == ItemStates.Running && State == ItemStates.Finished)
  423. {
  424. calflag = true;
  425. }
  426. return result;
  427. }
  428. protected override void OnExecuted(PointInfo args)
  429. {
  430. if (GeoFeature != null && Calculator != null && calflag)
  431. {
  432. Calculator.Calculate();
  433. }
  434. }
  435. internal static URMVesselMeasure CreateURMVesselMeasure(ItemMeta meta, IMeasureItem parent)
  436. {
  437. if (meta == null || meta.BaseType != MeasureTypes.URMVesselMeasure)
  438. {
  439. throw new ArgumentException();
  440. }
  441. var item = new URMVesselMeasure(meta, parent);
  442. item.Calculator = new URMVesselMeasureCal(item);
  443. return item;
  444. }
  445. internal class URMVesselMeasureCal : Calculator<URMVesselMeasure>
  446. {
  447. public URMVesselMeasureCal(URMVesselMeasure straightLine)
  448. : base(straightLine)
  449. {
  450. }
  451. public URMVesselMeasureCal()
  452. {
  453. }
  454. protected internal override string[] SupportedOutputKeys
  455. {
  456. get
  457. {
  458. return new[]
  459. {
  460. MeasureTerms.MaxVessDistance, MeasureTerms.MinVessDistance, MeasureTerms.MeanVessDistacne,MeasureTerms.StdVessDistance,
  461. MeasureTerms.MaxVessDiameter, MeasureTerms.MinVessDiameter, MeasureTerms.MeanVessDiameter,MeasureTerms.StdVessDiameter
  462. };
  463. }
  464. }
  465. protected override void OnCalculate()
  466. {
  467. StraightLineFeature feature = RefItem.GeoFeature;
  468. int width = 0;
  469. int height = 0;
  470. double UrmPhysicalwidth = 0;
  471. double UrmPhysicalheight = 0;
  472. NativeArray srcArray = new NativeArray(0);
  473. if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
  474. {
  475. var dicomvisual = feature.HostArea as ISRDicom;
  476. bool isSRDen = dicomvisual.isSRDen();
  477. if (!isSRDen)
  478. return;
  479. var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
  480. ref UrmPhysicalheight);
  481. //todo 坐标转换
  482. srcArray.Resize(dicomdate.Length);
  483. Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
  484. }
  485. else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
  486. {
  487. var modewithURM = feature.HostArea.Mode as IModeWithURM;
  488. if (modewithURM.URMStyle != "URM(Den)")
  489. return;
  490. var date = modewithURM.UrmArray;
  491. width = modewithURM.URMImgWidth;
  492. height = modewithURM.URMImgHeight;
  493. UrmPhysicalwidth = modewithURM.URMPhyWidth;
  494. UrmPhysicalheight = modewithURM.URMPhyHeight;
  495. srcArray.Resize(date.Length);
  496. Marshal.Copy(date, 0, srcArray.Start, date.Length);
  497. }
  498. else
  499. {
  500. return;
  501. }
  502. if (srcArray.Length != 8 * width * height)
  503. {
  504. _delayAction.BeginInvoke();
  505. return;
  506. }
  507. double regionwidth = feature.HostArea.ViewPort.Region.Width;
  508. double regionheight = feature.HostArea.ViewPort.Region.Height;
  509. DPoint startDPoint = SRPointTrans.TransPointS2I(feature.StartPoint, regionwidth, regionheight,
  510. UrmPhysicalwidth, UrmPhysicalheight, width, height);
  511. DPoint endDPoint = SRPointTrans.TransPointS2I(feature.EndPoint, regionwidth, regionheight,
  512. UrmPhysicalwidth, UrmPhysicalheight, width, height);
  513. if (startDPoint.X < 0 || startDPoint.X > width || endDPoint.X < 0 || endDPoint.X > width
  514. || startDPoint.Y < 0 || startDPoint.Y > height || endDPoint.Y < 0 || endDPoint.Y > height)
  515. return;
  516. List<DPoint> Points=new List<DPoint>();
  517. Points.Add(startDPoint);
  518. Points.Add(endDPoint);
  519. var cmlength=Math.Sqrt(Math.Pow((feature.StartPoint.X- feature.EndPoint.X),2)+Math.Pow((feature.StartPoint.Y - feature.EndPoint.Y), 2));
  520. var pixelscaler = UrmPhysicalwidth / width;
  521. int outPointNum = (int)(cmlength*1000);
  522. SRMeasurePoint[] outPoints=new SRMeasurePoint[outPointNum];
  523. var urmcal = feature.HostArea.Mode as IURMCal;
  524. if (urmcal == null)
  525. return;
  526. var result = urmcal.GetUrmVessMeasureResult(srcArray.Start, width, height, Points, pixelscaler, outPoints);
  527. foreach (var outputItem in Outputs)
  528. {
  529. outputItem.UpdateDescription(outputItem.Name);
  530. if (string.Equals(outputItem.Name, MeasureTerms.MaxVessDistance))
  531. {
  532. feature.UpdateValue(outputItem, RoundValue(result.MaxVessDistance, outputItem), Unit.mm);
  533. }
  534. else if (string.Equals(outputItem.Name, MeasureTerms.MinVessDistance))
  535. {
  536. feature.UpdateValue(outputItem, RoundValue(result.MinVessDistance, outputItem), Unit.mm);
  537. }
  538. else if (string.Equals(outputItem.Name, MeasureTerms.MeanVessDistacne))
  539. {
  540. feature.UpdateValue(outputItem, RoundValue(result.MeanVessDistacne, outputItem), Unit.mm);
  541. }
  542. else if (string.Equals(outputItem.Name, MeasureTerms.StdVessDistance))
  543. {
  544. feature.UpdateValue(outputItem, RoundValue(Math.Sqrt(result.VarianceVessDistance), outputItem), Unit.mm);
  545. }
  546. else if (string.Equals(outputItem.Name, MeasureTerms.MaxVessDiameter))
  547. {
  548. feature.UpdateValue(outputItem, RoundValue(result.MaxVessDiameter, outputItem), Unit.mm);
  549. }
  550. else if (string.Equals(outputItem.Name, MeasureTerms.MinVessDiameter))
  551. {
  552. feature.UpdateValue(outputItem, RoundValue(result.MinVessDiameter, outputItem), Unit.mm);
  553. }
  554. else if (string.Equals(outputItem.Name, MeasureTerms.MeanVessDiameter))
  555. {
  556. feature.UpdateValue(outputItem, RoundValue(result.MeanVessDiameter, outputItem), Unit.mm);
  557. }
  558. else if (string.Equals(outputItem.Name, MeasureTerms.StdVessDiameter))
  559. {
  560. feature.UpdateValue(outputItem, RoundValue(Math.Sqrt(result.VarianceVessDiameter), outputItem), Unit.mm);
  561. }
  562. }
  563. var maxPointIndex = result.MaxPos;
  564. var minPointIndex = result.MinPos;
  565. var srChart = ServiceManager.Instance.GetService<IMeasureService>().SrChart;
  566. srChart.Update(feature, outPoints.Select(x => new DPoint(x.X, x.Y)).ToArray(), maxPointIndex, minPointIndex);
  567. }
  568. }
  569. }
  570. internal class SRROIMeasure : Rect
  571. {
  572. private bool calflag=false;
  573. public SRROIMeasure(ItemMeta meta, IMeasureItem parent = null)
  574. : base(meta, parent)
  575. {
  576. }
  577. internal static SRROIMeasure CreateSRROIMeasure(ItemMeta meta, IMeasureItem parent)
  578. {
  579. if (meta == null || meta.BaseType != MeasureTypes.SRRoiDensity )
  580. {
  581. throw new ArgumentException();
  582. }
  583. var SRROI = new SRROIMeasure(meta, parent);
  584. SRROI.Calculator = new SRROICal(SRROI);
  585. return SRROI;
  586. }
  587. public override void DownloadValueFromPreviousItem()
  588. {
  589. }
  590. protected override bool OnExecute(PointInfo args)
  591. {
  592. var cal = Calculator as SRROICal;
  593. if (args.VisualArea is ISRDicom)
  594. {
  595. var dicomvisual = args.VisualArea as ISRDicom;
  596. bool isSRDen = dicomvisual.isSRDen();
  597. if (args.VisualArea.Mode == null || !isSRDen)
  598. {
  599. return false;
  600. }
  601. }
  602. else
  603. {
  604. var modewithurm = args.VisualArea.Mode as IModeWithURM;
  605. if (modewithurm == null || modewithurm?.URMStyle != "URM(Den)")
  606. return false;
  607. }
  608. calflag = false;
  609. cal.calflag = false;
  610. var preState = State;
  611. var result = base.OnExecute(args);
  612. if (result && preState == ItemStates.Running && State == ItemStates.Finished)
  613. {
  614. calflag = true;
  615. cal.calflag = true;
  616. }
  617. return result;
  618. }
  619. protected override void OnExecuted(PointInfo args)
  620. {
  621. if (GeoFeature != null && Calculator != null && calflag)
  622. {
  623. Calculator.Calculate();
  624. }
  625. }
  626. internal sealed class SRROICal : Calculator<SRROIMeasure>
  627. {
  628. public bool calflag=false;
  629. public SRROICal(SRROIMeasure item)
  630. : base(item)
  631. {
  632. }
  633. public SRROICal()
  634. {
  635. }
  636. protected internal override string[] SupportedOutputKeys
  637. {
  638. get
  639. {
  640. return new[]
  641. {
  642. MeasureTerms.URMDenROI
  643. };
  644. }
  645. }
  646. protected override void OnCalculate()
  647. {
  648. if(!calflag)
  649. return;
  650. RectFeature feature = RefItem.GeoFeature;
  651. int width = 0;
  652. int height = 0;
  653. double UrmPhysicalwidth = 0;
  654. double UrmPhysicalheight = 0;
  655. NativeArray srcArray = new NativeArray(0);
  656. if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
  657. {
  658. var dicomvisual = feature.HostArea as ISRDicom;
  659. bool isSRDen = dicomvisual.isSRDen();
  660. if (!isSRDen)
  661. return;
  662. var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
  663. ref UrmPhysicalheight);
  664. //todo 坐标转换
  665. srcArray.Resize(dicomdate.Length);
  666. Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
  667. }
  668. else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
  669. {
  670. var modewithURM = feature.HostArea.Mode as IModeWithURM;
  671. if (modewithURM.URMStyle != "URM(Den)")
  672. return;
  673. var date = modewithURM.UrmArray;
  674. width = modewithURM.URMImgWidth;
  675. height = modewithURM.URMImgHeight;
  676. UrmPhysicalwidth = modewithURM.URMPhyWidth;
  677. UrmPhysicalheight = modewithURM.URMPhyHeight;
  678. srcArray.Resize(date.Length);
  679. Marshal.Copy(date, 0, srcArray.Start, date.Length);
  680. }
  681. else
  682. {
  683. return;
  684. }
  685. if (srcArray.Length != 8 * width * height)
  686. {
  687. _delayAction.BeginInvoke();
  688. return;
  689. }
  690. //todo 坐标转换
  691. double regionwidth = feature.HostArea.ViewPort.Region.Width;
  692. double regionheight = feature.HostArea.ViewPort.Region.Height;
  693. DPoint startDPoint = SRPointTrans.TransPointS2I(feature.TopLeft, regionwidth, regionheight,
  694. UrmPhysicalwidth, UrmPhysicalheight, width, height);
  695. DPoint endDPoint = SRPointTrans.TransPointS2I(feature.BottomRight, regionwidth, regionheight,
  696. UrmPhysicalwidth, UrmPhysicalheight, width, height);
  697. if (startDPoint.X < 0 || startDPoint.X > width || endDPoint.X < 0 || endDPoint.X > width
  698. || startDPoint.Y < 0 || startDPoint.Y > height || endDPoint.Y < 0 || endDPoint.Y > height)
  699. return;
  700. int outPointsNum = 0;
  701. var urmcal = feature.HostArea.Mode as IURMCal;
  702. if (urmcal == null)
  703. return;
  704. double roivel = urmcal.GetSRRoiVel(srcArray.Start, width, height, startDPoint.X,
  705. startDPoint.Y, endDPoint.X, endDPoint.Y);
  706. Outputs[0].UpdateDescription(Outputs[0].Name);
  707. feature.UpdateValue(Outputs[0], RoundValue(roivel * 100, GetResultDigits(PrimaryOutput)), Unit.percent);
  708. }
  709. }
  710. }
  711. internal class URMRectDenMeasure : Rect
  712. {
  713. private bool calflag = false;
  714. public URMRectDenMeasure(ItemMeta meta, IMeasureItem parent = null)
  715. : base(meta, parent)
  716. {
  717. }
  718. internal static URMRectDenMeasure CreateURMRectDenMeasure(ItemMeta meta, IMeasureItem parent)
  719. {
  720. if (meta == null || meta.BaseType != MeasureTypes.URMRectDenMeasure)
  721. {
  722. throw new ArgumentException();
  723. }
  724. var item = new URMRectDenMeasure(meta, parent);
  725. item.Calculator = new URMRectDenMeasureCal(item);
  726. return item;
  727. }
  728. public override void DownloadValueFromPreviousItem()
  729. {
  730. }
  731. protected override bool OnExecute(PointInfo args)
  732. {
  733. var cal = Calculator as URMRectDenMeasureCal;
  734. if (args.VisualArea is ISRDicom)
  735. {
  736. var dicomvisual = args.VisualArea as ISRDicom;
  737. bool isSRDen = dicomvisual.isSRDen();
  738. if (args.VisualArea.Mode == null || !isSRDen)
  739. {
  740. return false;
  741. }
  742. }
  743. else
  744. {
  745. var modewithurm = args.VisualArea.Mode as IModeWithURM;
  746. if (modewithurm == null || modewithurm?.URMStyle != "URM(Den)")
  747. return false;
  748. }
  749. calflag = false;
  750. cal.calflag = false;
  751. var preState = State;
  752. var result = base.OnExecute(args);
  753. if (result && preState == ItemStates.Running && State == ItemStates.Finished)
  754. {
  755. calflag = true;
  756. cal.calflag = true;
  757. }
  758. return result;
  759. }
  760. protected override void OnExecuted(PointInfo args)
  761. {
  762. if (GeoFeature != null && Calculator != null && calflag)
  763. {
  764. Calculator.Calculate();
  765. }
  766. }
  767. internal sealed class URMRectDenMeasureCal : Calculator<URMRectDenMeasure>
  768. {
  769. public bool calflag = false;
  770. public URMRectDenMeasureCal(URMRectDenMeasure item)
  771. : base(item)
  772. {
  773. }
  774. public URMRectDenMeasureCal()
  775. {
  776. }
  777. protected internal override string[] SupportedOutputKeys
  778. {
  779. get
  780. {
  781. return new[]
  782. {
  783. MeasureTerms.URMDenROI, MeasureTerms.URMDenFractalDim, MeasureTerms.URMDenMax,
  784. MeasureTerms.URMDenMin, MeasureTerms.URMDenMean, MeasureTerms.URMDenStd, MeasureTerms.Area,
  785. MeasureTerms.URMDenROIIn, MeasureTerms.URMDenFractalDimIn, MeasureTerms.URMDenMaxIn,
  786. MeasureTerms.URMDenMinIn, MeasureTerms.URMDenMeanIn, MeasureTerms.URMDenStdIn, MeasureTerms.URMAreaIn,
  787. MeasureTerms.URMDenROIOut, MeasureTerms.URMDenFractalDimOut, MeasureTerms.URMDenMaxOut,
  788. MeasureTerms.URMDenMinOut, MeasureTerms.URMDenMeanOut, MeasureTerms.URMDenStdOut, MeasureTerms.URMAreaOut,
  789. };
  790. }
  791. }
  792. protected override void OnCalculate()
  793. {
  794. if (!calflag)
  795. return;
  796. RectFeature feature = RefItem.GeoFeature;
  797. int width = 0;
  798. int height = 0;
  799. double UrmPhysicalwidth = 0;
  800. double UrmPhysicalheight = 0;
  801. NativeArray srcArray = new NativeArray(0);
  802. if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
  803. {
  804. var dicomvisual = feature.HostArea as ISRDicom;
  805. bool isSRDen = dicomvisual.isSRDen();
  806. if (!isSRDen)
  807. return;
  808. var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
  809. ref UrmPhysicalheight);
  810. //todo 坐标转换
  811. srcArray.Resize(dicomdate.Length);
  812. Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
  813. }
  814. else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
  815. {
  816. var modewithURM = feature.HostArea.Mode as IModeWithURM;
  817. if (modewithURM.URMStyle != "URM(Den)")
  818. return;
  819. var date = modewithURM.UrmArray;
  820. width = modewithURM.URMImgWidth;
  821. height = modewithURM.URMImgHeight;
  822. UrmPhysicalwidth = modewithURM.URMPhyWidth;
  823. UrmPhysicalheight = modewithURM.URMPhyHeight;
  824. srcArray.Resize(date.Length);
  825. Marshal.Copy(date, 0, srcArray.Start, date.Length);
  826. }
  827. else
  828. {
  829. return;
  830. }
  831. if (srcArray.Length != 8 * width * height)
  832. {
  833. _delayAction.BeginInvoke();
  834. return;
  835. }
  836. //todo 坐标转换
  837. double regionwidth = feature.HostArea.ViewPort.Region.Width;
  838. double regionheight = feature.HostArea.ViewPort.Region.Height;
  839. DPoint startDPoint = SRPointTrans.TransPointS2I(feature.TopLeft, regionwidth, regionheight,
  840. UrmPhysicalwidth, UrmPhysicalheight, width, height);
  841. DPoint endDPoint = SRPointTrans.TransPointS2I(feature.BottomRight, regionwidth, regionheight,
  842. UrmPhysicalwidth, UrmPhysicalheight, width, height);
  843. if (startDPoint.X < 0 || startDPoint.X > width || endDPoint.X < 0 || endDPoint.X > width
  844. || startDPoint.Y < 0 || startDPoint.Y > height || endDPoint.Y < 0 || endDPoint.Y > height)
  845. return;
  846. List<DPoint> ImagePoint = new List<DPoint>();
  847. double areaScaler = (UrmPhysicalwidth / width) * (UrmPhysicalheight / height);
  848. ImagePoint.Add(startDPoint);
  849. ImagePoint.Add(endDPoint);
  850. var urmcal = feature.HostArea.Mode as IURMCal;
  851. if (urmcal == null)
  852. return;
  853. var result = urmcal.GetURMDenMeasureResult(srcArray.Start, width, height, ImagePoint,areaScaler);
  854. foreach (var outputItem in Outputs)
  855. {
  856. outputItem.UpdateDescription(outputItem.Name);
  857. if (string.Equals(outputItem.Name,MeasureTerms.URMDenROI))
  858. {
  859. feature.UpdateValue(outputItem, RoundValue(result.RoiDen*100, outputItem), Unit.percent);
  860. }
  861. else if (string.Equals(outputItem.Name, MeasureTerms.URMDenFractalDim))
  862. {
  863. feature.UpdateValue(outputItem, RoundValue(result.RoiFractalDim, outputItem), Unit.None);
  864. }
  865. else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMax))
  866. {
  867. feature.UpdateValue(outputItem, RoundValue(result.MaxDensity, outputItem), Unit.None);
  868. }
  869. else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMin))
  870. {
  871. feature.UpdateValue(outputItem, RoundValue(result.MinDensity, outputItem), Unit.None);
  872. }
  873. else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMean))
  874. {
  875. feature.UpdateValue(outputItem, RoundValue(result.MeanDensity, outputItem), Unit.None);
  876. }
  877. else if (string.Equals(outputItem.Name, MeasureTerms.URMDenStd))
  878. {
  879. feature.UpdateValue(outputItem, RoundValue(Math.Sqrt(result.VarianceDensity), outputItem), Unit.None);
  880. }
  881. else if (string.Equals(outputItem.Name, MeasureTerms.Area))
  882. {
  883. feature.UpdateValue(outputItem, RoundValue(result.RoiArea, outputItem), Unit.cm2);
  884. }
  885. }
  886. }
  887. }
  888. }
  889. internal class URMRectVelMeasure : Rect
  890. {
  891. private bool calflag = false;
  892. public URMRectVelMeasure(ItemMeta meta, IMeasureItem parent = null)
  893. : base(meta, parent)
  894. {
  895. }
  896. internal static URMRectVelMeasure CreateURMRectVelMeasure(ItemMeta meta, IMeasureItem parent)
  897. {
  898. if (meta == null || meta.BaseType != MeasureTypes.URMRectVelMeasure)
  899. {
  900. throw new ArgumentException();
  901. }
  902. var item = new URMRectVelMeasure(meta, parent);
  903. item.Calculator = new URMRectVelMeasureCal(item);
  904. return item;
  905. }
  906. public override void DownloadValueFromPreviousItem()
  907. {
  908. }
  909. protected override bool OnExecute(PointInfo args)
  910. {
  911. var cal = Calculator as URMRectVelMeasureCal;
  912. if (args.VisualArea is ISRDicom)
  913. {
  914. var dicomvisual = args.VisualArea as ISRDicom;
  915. bool isSrVel = dicomvisual.isSRVel();
  916. if (args.VisualArea.Mode == null || !isSrVel)
  917. {
  918. return false;
  919. }
  920. }
  921. else
  922. {
  923. var modewithurm = args.VisualArea.Mode as IModeWithURM;
  924. if (modewithurm == null || modewithurm?.URMStyle != "URM(Vel)")
  925. return false;
  926. }
  927. calflag = false;
  928. cal.calflag = false;
  929. var preState = State;
  930. var result = base.OnExecute(args);
  931. if (result && preState == ItemStates.Running && State == ItemStates.Finished)
  932. {
  933. calflag = true;
  934. cal.calflag = true;
  935. }
  936. return result;
  937. }
  938. protected override void OnExecuted(PointInfo args)
  939. {
  940. if (GeoFeature != null && Calculator != null && calflag)
  941. {
  942. Calculator.Calculate();
  943. }
  944. }
  945. internal sealed class URMRectVelMeasureCal : Calculator<URMRectVelMeasure>
  946. {
  947. public bool calflag = false;
  948. public URMRectVelMeasureCal(URMRectVelMeasure item)
  949. : base(item)
  950. {
  951. }
  952. public URMRectVelMeasureCal()
  953. {
  954. }
  955. protected internal override string[] SupportedOutputKeys
  956. {
  957. get
  958. {
  959. return new[]
  960. {
  961. MeasureTerms.URMVelMax, MeasureTerms.URMVelMin, MeasureTerms.URMVelMean, MeasureTerms.URMVelStd, MeasureTerms.Area,
  962. MeasureTerms.URMVelMaxIn, MeasureTerms.URMVelMinIn, MeasureTerms.URMVelMeanIn, MeasureTerms.URMVelStdIn, MeasureTerms.URMAreaIn,
  963. MeasureTerms.URMVelMaxOut, MeasureTerms.URMVelMinOut, MeasureTerms.URMVelMeanOut, MeasureTerms.URMVelStdOut, MeasureTerms.URMAreaOut,
  964. };
  965. }
  966. }
  967. protected override void OnCalculate()
  968. {
  969. if (!calflag)
  970. return;
  971. RectFeature feature = RefItem.GeoFeature;
  972. int width = 0;
  973. int height = 0;
  974. double UrmPhysicalwidth = 0;
  975. double UrmPhysicalheight = 0;
  976. double UrmMinVel = 0;
  977. NativeArray srcArray = new NativeArray(0);
  978. if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
  979. {
  980. var dicomvisual = feature.HostArea as ISRDicom;
  981. bool isSRVel = dicomvisual.isSRVel();
  982. if (!isSRVel)
  983. return;
  984. var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
  985. ref UrmPhysicalheight);
  986. //todo 坐标转换
  987. srcArray.Resize(dicomdate.Length);
  988. Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
  989. UrmMinVel = dicomvisual.GetSRMinVel();
  990. }
  991. else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
  992. {
  993. var modewithURM = feature.HostArea.Mode as IModeWithURM;
  994. if (modewithURM.URMStyle != "URM(Vel)")
  995. return;
  996. var date = modewithURM.UrmArray;
  997. width = modewithURM.URMImgWidth;
  998. height = modewithURM.URMImgHeight;
  999. UrmPhysicalwidth = modewithURM.URMPhyWidth;
  1000. UrmPhysicalheight = modewithURM.URMPhyHeight;
  1001. UrmMinVel = modewithURM.URMMinVel;
  1002. srcArray.Resize(date.Length);
  1003. Marshal.Copy(date, 0, srcArray.Start, date.Length);
  1004. }
  1005. else
  1006. {
  1007. return;
  1008. }
  1009. //todo 坐标转换
  1010. double regionwidth = feature.HostArea.ViewPort.Region.Width;
  1011. double regionheight = feature.HostArea.ViewPort.Region.Height;
  1012. DPoint startDPoint = SRPointTrans.TransPointS2I(feature.TopLeft, regionwidth, regionheight,
  1013. UrmPhysicalwidth, UrmPhysicalheight, width, height);
  1014. DPoint endDPoint = SRPointTrans.TransPointS2I(feature.BottomRight, regionwidth, regionheight,
  1015. UrmPhysicalwidth, UrmPhysicalheight, width, height);
  1016. if (startDPoint.X < 0 || startDPoint.X > width || endDPoint.X < 0 || endDPoint.X > width
  1017. || startDPoint.Y < 0 || startDPoint.Y > height || endDPoint.Y < 0 || endDPoint.Y > height)
  1018. return;
  1019. List<DPoint> ImagePoint = new List<DPoint>();
  1020. double areaScaler = (UrmPhysicalwidth / width) * (UrmPhysicalheight / height);
  1021. ImagePoint.Add(startDPoint);
  1022. ImagePoint.Add(endDPoint);
  1023. var urmcal = feature.HostArea.Mode as IURMCal;
  1024. if (urmcal == null)
  1025. return;
  1026. var result = urmcal.GetURMVelMeasureResult(srcArray.Start, width, height, ImagePoint, areaScaler);
  1027. foreach (var outputItem in Outputs)
  1028. {
  1029. outputItem.UpdateDescription(outputItem.Name);
  1030. if (string.Equals(outputItem.Name, MeasureTerms.URMVelMax))
  1031. {
  1032. feature.UpdateValue(outputItem, RoundValue(result.MaxVel+UrmMinVel, outputItem), Unit.mms);
  1033. }
  1034. else if (string.Equals(outputItem.Name, MeasureTerms.URMVelMin))
  1035. {
  1036. feature.UpdateValue(outputItem, RoundValue(result.MinVel + UrmMinVel, outputItem), Unit.mms);
  1037. }
  1038. else if (string.Equals(outputItem.Name, MeasureTerms.URMVelMean))
  1039. {
  1040. feature.UpdateValue(outputItem, RoundValue(result.MeanVel + UrmMinVel, outputItem), Unit.mms);
  1041. }
  1042. else if (string.Equals(outputItem.Name, MeasureTerms.URMVelStd))
  1043. {
  1044. feature.UpdateValue(outputItem, RoundValue(Math.Sqrt(result.VarianceVel), outputItem), Unit.mms);
  1045. }
  1046. else if (string.Equals(outputItem.Name, MeasureTerms.Area))
  1047. {
  1048. feature.UpdateValue(outputItem, RoundValue(result.RoiArea, outputItem), Unit.cm2);
  1049. }
  1050. }
  1051. }
  1052. }
  1053. }
  1054. internal class URMTraceDenMeasure : Trace
  1055. {
  1056. private bool calflag = false;
  1057. public URMTraceDenMeasure(ItemMeta meta, IMeasureItem parent = null)
  1058. : base(meta, parent)
  1059. {
  1060. }
  1061. internal static URMTraceDenMeasure CreateURMTraceDenMeasure(ItemMeta meta, IMeasureItem parent)
  1062. {
  1063. if (meta == null || meta.BaseType != MeasureTypes.URMTraceDenMeasure)
  1064. {
  1065. throw new ArgumentException();
  1066. }
  1067. meta.AddArgs(new MeasureParam(IsAutoSnapKey, "true", DefinitionPriorityEnum.Root));
  1068. var item = new URMTraceDenMeasure(meta, parent);
  1069. item.Calculator = new URMTraceDenMeasureCal(item);
  1070. return item;
  1071. }
  1072. public override void DownloadValueFromPreviousItem()
  1073. {
  1074. }
  1075. protected override bool OnExecute(PointInfo args)
  1076. {
  1077. var cal = Calculator as URMTraceDenMeasureCal;
  1078. if (args.VisualArea is ISRDicom)
  1079. {
  1080. var dicomvisual = args.VisualArea as ISRDicom;
  1081. bool isSRDen = dicomvisual.isSRDen();
  1082. if (args.VisualArea.Mode == null || !isSRDen)
  1083. {
  1084. return false;
  1085. }
  1086. }
  1087. else
  1088. {
  1089. var modewithurm = args.VisualArea.Mode as IModeWithURM;
  1090. if (modewithurm == null || modewithurm?.URMStyle != "URM(Den)")
  1091. return false;
  1092. }
  1093. calflag = false;
  1094. cal.calflag = false;
  1095. var preState = State;
  1096. var result = base.OnExecute(args);
  1097. if (result && preState == ItemStates.Running && State == ItemStates.Finished)
  1098. {
  1099. calflag = true;
  1100. cal.calflag = true;
  1101. }
  1102. return result;
  1103. }
  1104. protected override void OnExecuted(PointInfo args)
  1105. {
  1106. if (GeoFeature != null && Calculator != null && calflag)
  1107. {
  1108. Calculator.Calculate();
  1109. }
  1110. }
  1111. internal sealed class URMTraceDenMeasureCal : Calculator<URMTraceDenMeasure>
  1112. {
  1113. public bool calflag = false;
  1114. public URMTraceDenMeasureCal(URMTraceDenMeasure item)
  1115. : base(item)
  1116. {
  1117. }
  1118. public URMTraceDenMeasureCal()
  1119. {
  1120. }
  1121. protected internal override string[] SupportedOutputKeys
  1122. {
  1123. get
  1124. {
  1125. return new[]
  1126. {
  1127. MeasureTerms.URMDenROI, MeasureTerms.URMDenFractalDim, MeasureTerms.URMDenMax,
  1128. MeasureTerms.URMDenMin, MeasureTerms.URMDenMean, MeasureTerms.URMDenStd,
  1129. MeasureTerms.Area
  1130. };
  1131. }
  1132. }
  1133. protected override void OnCalculate()
  1134. {
  1135. if (!calflag)
  1136. return;
  1137. PolyLineFeature feature = RefItem.GeoFeature;
  1138. int width = 0;
  1139. int height = 0;
  1140. double UrmPhysicalwidth = 0;
  1141. double UrmPhysicalheight = 0;
  1142. NativeArray srcArray = new NativeArray(0);
  1143. if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
  1144. {
  1145. var dicomvisual = feature.HostArea as ISRDicom;
  1146. bool isSRDen = dicomvisual.isSRDen();
  1147. if (!isSRDen)
  1148. return;
  1149. var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
  1150. ref UrmPhysicalheight);
  1151. //todo 坐标转换
  1152. srcArray.Resize(dicomdate.Length);
  1153. Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
  1154. }
  1155. else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
  1156. {
  1157. var modewithURM = feature.HostArea.Mode as IModeWithURM;
  1158. if (modewithURM.URMStyle != "URM(Den)")
  1159. return;
  1160. var date = modewithURM.UrmArray;
  1161. width = modewithURM.URMImgWidth;
  1162. height = modewithURM.URMImgHeight;
  1163. UrmPhysicalwidth = modewithURM.URMPhyWidth;
  1164. UrmPhysicalheight = modewithURM.URMPhyHeight;
  1165. srcArray.Resize(date.Length);
  1166. Marshal.Copy(date, 0, srcArray.Start, date.Length);
  1167. }
  1168. else
  1169. {
  1170. return;
  1171. }
  1172. if (srcArray.Length != 8 * width * height)
  1173. {
  1174. _delayAction.BeginInvoke();
  1175. return;
  1176. }
  1177. //todo 坐标转换
  1178. double regionwidth = feature.HostArea.ViewPort.Region.Width;
  1179. double regionheight = feature.HostArea.ViewPort.Region.Height;
  1180. var points = RefItem.GeoFeature.Points;
  1181. List<DPoint> ImagePoint = new List<DPoint>();
  1182. for (int i = 0; i < points.Count; i++)
  1183. {
  1184. var point = SRPointTrans.TransPointS2I(points[i], regionwidth, regionheight,
  1185. UrmPhysicalwidth, UrmPhysicalheight, width, height);
  1186. if (point.X < 0 || point.X > width || point.X < 0 || point.X > width)
  1187. continue;
  1188. ImagePoint.Add(point);
  1189. }
  1190. double areaScaler = (UrmPhysicalwidth / width) * (UrmPhysicalheight / height);
  1191. var urmcal = feature.HostArea.Mode as IURMCal;
  1192. if (urmcal == null)
  1193. return;
  1194. var result = urmcal.GetURMDenMeasureResult(srcArray.Start, width, height, ImagePoint, areaScaler);
  1195. foreach (var outputItem in Outputs)
  1196. {
  1197. outputItem.UpdateDescription(outputItem.Name);
  1198. if (string.Equals(outputItem.Name, MeasureTerms.URMDenROI))
  1199. {
  1200. feature.UpdateValue(outputItem, RoundValue(result.RoiDen*100, outputItem), Unit.percent);
  1201. }
  1202. else if (string.Equals(outputItem.Name, MeasureTerms.URMDenFractalDim))
  1203. {
  1204. feature.UpdateValue(outputItem, RoundValue(result.RoiFractalDim, outputItem), Unit.None);
  1205. }
  1206. else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMax))
  1207. {
  1208. feature.UpdateValue(outputItem, RoundValue(result.MaxDensity, outputItem), Unit.None);
  1209. }
  1210. else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMin))
  1211. {
  1212. feature.UpdateValue(outputItem, RoundValue(result.MinDensity, outputItem), Unit.None);
  1213. }
  1214. else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMean))
  1215. {
  1216. feature.UpdateValue(outputItem, RoundValue(result.MeanDensity, outputItem), Unit.None);
  1217. }
  1218. else if (string.Equals(outputItem.Name, MeasureTerms.URMDenStd))
  1219. {
  1220. feature.UpdateValue(outputItem, RoundValue(Math.Sqrt(result.VarianceDensity), outputItem), Unit.None);
  1221. }
  1222. else if (string.Equals(outputItem.Name, MeasureTerms.Area))
  1223. {
  1224. feature.UpdateValue(outputItem, RoundValue(result.RoiArea, outputItem), Unit.cm2);
  1225. }
  1226. }
  1227. }
  1228. }
  1229. }
  1230. internal class URMTraceVelMeasure : Trace
  1231. {
  1232. private bool calflag = false;
  1233. public URMTraceVelMeasure(ItemMeta meta, IMeasureItem parent = null)
  1234. : base(meta, parent)
  1235. {
  1236. }
  1237. internal static URMTraceVelMeasure CreateURMTraceVelMeasure(ItemMeta meta, IMeasureItem parent)
  1238. {
  1239. if (meta == null || meta.BaseType != MeasureTypes.URMTraceVelMeasure)
  1240. {
  1241. throw new ArgumentException();
  1242. }
  1243. meta.AddArgs(new MeasureParam(IsAutoSnapKey, "true", DefinitionPriorityEnum.Root));
  1244. var item = new URMTraceVelMeasure(meta, parent);
  1245. item.Calculator = new URMTraceVelMeasureCal(item);
  1246. return item;
  1247. }
  1248. public override void DownloadValueFromPreviousItem()
  1249. {
  1250. }
  1251. protected override bool OnExecute(PointInfo args)
  1252. {
  1253. var cal = Calculator as URMTraceVelMeasureCal;
  1254. if (args.VisualArea is ISRDicom)
  1255. {
  1256. var dicomvisual = args.VisualArea as ISRDicom;
  1257. bool isSrVel = dicomvisual.isSRVel();
  1258. if (args.VisualArea.Mode == null || !isSrVel)
  1259. {
  1260. return false;
  1261. }
  1262. }
  1263. else
  1264. {
  1265. var modewithurm = args.VisualArea.Mode as IModeWithURM;
  1266. if (modewithurm == null || modewithurm?.URMStyle != "URM(Vel)")
  1267. return false;
  1268. }
  1269. calflag = false;
  1270. cal.calflag = false;
  1271. var preState = State;
  1272. var result = base.OnExecute(args);
  1273. if (result && preState == ItemStates.Running && State == ItemStates.Finished)
  1274. {
  1275. calflag = true;
  1276. cal.calflag = true;
  1277. }
  1278. return result;
  1279. }
  1280. protected override void OnExecuted(PointInfo args)
  1281. {
  1282. if (GeoFeature != null && Calculator != null && calflag)
  1283. {
  1284. Calculator.Calculate();
  1285. }
  1286. }
  1287. internal sealed class URMTraceVelMeasureCal : Calculator<URMTraceVelMeasure>
  1288. {
  1289. public bool calflag = false;
  1290. public URMTraceVelMeasureCal(URMTraceVelMeasure item)
  1291. : base(item)
  1292. {
  1293. }
  1294. public URMTraceVelMeasureCal()
  1295. {
  1296. }
  1297. protected internal override string[] SupportedOutputKeys
  1298. {
  1299. get
  1300. {
  1301. return new[]
  1302. {
  1303. MeasureTerms.URMVelMax, MeasureTerms.URMVelMin, MeasureTerms.URMVelMean, MeasureTerms.URMVelStd,
  1304. MeasureTerms.Area
  1305. };
  1306. }
  1307. }
  1308. protected override void OnCalculate()
  1309. {
  1310. if (!calflag)
  1311. return;
  1312. PolyLineFeature feature = RefItem.GeoFeature;
  1313. int width = 0;
  1314. int height = 0;
  1315. double UrmPhysicalwidth = 0;
  1316. double UrmPhysicalheight = 0;
  1317. double UrmMinVel = 0;
  1318. NativeArray srcArray = new NativeArray(0);
  1319. if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
  1320. {
  1321. var dicomvisual = feature.HostArea as ISRDicom;
  1322. bool isSRVel = dicomvisual.isSRVel();
  1323. if (!isSRVel)
  1324. return;
  1325. var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
  1326. ref UrmPhysicalheight);
  1327. //todo 坐标转换
  1328. srcArray.Resize(dicomdate.Length);
  1329. Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
  1330. UrmMinVel = dicomvisual.GetSRMinVel();
  1331. }
  1332. else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
  1333. {
  1334. var modewithURM = feature.HostArea.Mode as IModeWithURM;
  1335. if (modewithURM.URMStyle != "URM(Vel)")
  1336. return;
  1337. var date = modewithURM.UrmArray;
  1338. width = modewithURM.URMImgWidth;
  1339. height = modewithURM.URMImgHeight;
  1340. UrmPhysicalwidth = modewithURM.URMPhyWidth;
  1341. UrmPhysicalheight = modewithURM.URMPhyHeight;
  1342. UrmMinVel = modewithURM.URMMinVel;
  1343. srcArray.Resize(date.Length);
  1344. Marshal.Copy(date, 0, srcArray.Start, date.Length);
  1345. }
  1346. else
  1347. {
  1348. return;
  1349. }
  1350. //todo 坐标转换
  1351. double regionwidth = feature.HostArea.ViewPort.Region.Width;
  1352. double regionheight = feature.HostArea.ViewPort.Region.Height;
  1353. var points = RefItem.GeoFeature.Points;
  1354. List<DPoint> ImagePoint = new List<DPoint>();
  1355. for (int i = 0; i < points.Count; i++)
  1356. {
  1357. var point = SRPointTrans.TransPointS2I(points[i], regionwidth, regionheight,
  1358. UrmPhysicalwidth, UrmPhysicalheight, width, height);
  1359. if (point.X < 0 || point.X > width || point.X < 0 || point.X > width)
  1360. continue;
  1361. ImagePoint.Add(point);
  1362. }
  1363. double areaScaler = (UrmPhysicalwidth / width) * (UrmPhysicalheight / height);
  1364. var urmcal = feature.HostArea.Mode as IURMCal;
  1365. if (urmcal == null)
  1366. return;
  1367. var result = urmcal.GetURMVelMeasureResult(srcArray.Start, width, height, ImagePoint, areaScaler);
  1368. foreach (var outputItem in Outputs)
  1369. {
  1370. outputItem.UpdateDescription(outputItem.Name);
  1371. if (string.Equals(outputItem.Name, MeasureTerms.URMVelMax))
  1372. {
  1373. feature.UpdateValue(outputItem, RoundValue(result.MaxVel + UrmMinVel, outputItem), Unit.mms);
  1374. }
  1375. else if (string.Equals(outputItem.Name, MeasureTerms.URMVelMin))
  1376. {
  1377. feature.UpdateValue(outputItem, RoundValue(result.MinVel + UrmMinVel, outputItem), Unit.mms);
  1378. }
  1379. else if (string.Equals(outputItem.Name, MeasureTerms.URMVelMean))
  1380. {
  1381. feature.UpdateValue(outputItem, RoundValue(result.MeanVel + UrmMinVel, outputItem), Unit.mms);
  1382. }
  1383. else if (string.Equals(outputItem.Name, MeasureTerms.URMVelStd))
  1384. {
  1385. feature.UpdateValue(outputItem, RoundValue(Math.Sqrt(result.VarianceVel), outputItem), Unit.mms);
  1386. }
  1387. else if (string.Equals(outputItem.Name, MeasureTerms.Area))
  1388. {
  1389. feature.UpdateValue(outputItem, RoundValue(result.RoiArea, outputItem), Unit.cm2);
  1390. }
  1391. }
  1392. }
  1393. }
  1394. }
  1395. public class URMShellMeasure : Trace
  1396. {
  1397. private bool _isSmartMove;
  1398. public FloatParameter ShellWidth { get; set; }
  1399. internal static readonly string ShellWidthKey = "ShellWidth";
  1400. internal static readonly string ShellWidthMetaKey = "ShellWidth_Meta";
  1401. public static string ShellWidthMeta = "[1 2 3 4 5]";
  1402. public static string ShellWidthDefaultValue = "1";
  1403. public URMShellMeasure(ItemMeta meta, IMeasureItem parent = null)
  1404. : base(meta, parent)
  1405. {
  1406. if (!meta.TryGetArgValue(ShellWidthMetaKey, out var shellWidthMeta) || string.IsNullOrEmpty(shellWidthMeta))
  1407. {
  1408. shellWidthMeta = ShellWidthMeta;
  1409. }
  1410. if (!meta.TryGetArgValue(ShellWidthKey, out var shellWidthDefaultValue) || string.IsNullOrEmpty(shellWidthDefaultValue))
  1411. {
  1412. shellWidthDefaultValue = ShellWidthDefaultValue;
  1413. }
  1414. ShellWidth = CreateArrayFloatParam(ShellWidthKey, shellWidthMeta, shellWidthDefaultValue);
  1415. ShellWidth.ValueChanged += OnShellWidthParamsChanged;
  1416. }
  1417. protected override bool OnExecuteMouse(PointInfo args)
  1418. {
  1419. if (args != null && (State == ItemStates.Waiting || State == ItemStates.Running || State == ItemStates.Finished))
  1420. {
  1421. bool completed = false;
  1422. if (State == ItemStates.Finished)
  1423. {
  1424. switch (args.Action)
  1425. {
  1426. case PointAction.MouseMove:
  1427. case PointAction.MouseUp:
  1428. return false;
  1429. case PointAction.MouseDown:
  1430. HandleMouseDownWhileFinished();
  1431. break;
  1432. }
  1433. }
  1434. if (State == ItemStates.Waiting)
  1435. {
  1436. switch (args.Action)
  1437. {
  1438. case PointAction.MouseMove:
  1439. case PointAction.MouseUp:
  1440. return false;
  1441. case PointAction.MouseDown:
  1442. HandleMouseDownWhileWaiting((MultiRegionPointInfo)args,
  1443. (vertices, refItem, xUnit, yUnit) => new ShellTraceFeature(vertices, refItem, xUnit, yUnit));
  1444. FirstPoint = args;
  1445. if (!args.PixelPerX.AlmostEquals(0))
  1446. {
  1447. float pixelThreshold = PixelThreshold.AlmostEquals(0) ? 4 : PixelThreshold;
  1448. Threshold = (float)(pixelThreshold / args.PixelPerX);
  1449. }
  1450. break;
  1451. }
  1452. }
  1453. else if (State == ItemStates.Running)
  1454. {
  1455. var points = (MultiRegionPointInfo)args;
  1456. if (!GeoFeature.AnyExist(points.AllAreas))
  1457. {
  1458. return false;
  1459. }
  1460. switch (args.Action)
  1461. {
  1462. case PointAction.MouseDown:
  1463. IsClosed = true;
  1464. GeoFeature.IsClosed = true;
  1465. completed = true;
  1466. break;
  1467. case PointAction.MouseMove:
  1468. //Use the IsAutoSnap to check if the trace need to use smart move.
  1469. var measureService = ServiceManager.Instance.GetService<IMeasureService>();
  1470. double autoSnapThreshold = measureService.Settings.AutoSnapThreshold;
  1471. if (IsAutoSnap && autoSnapThreshold > 0)
  1472. {
  1473. //Change autosnapdistance unit from cm to pixel
  1474. if (FirstPoint != null)
  1475. {
  1476. var current = points.AllRegionPoints.FirstOrDefault(x => x.VisualArea == FirstPoint.VisualArea);
  1477. if (current != null)
  1478. {
  1479. var length = (FirstPoint.PhyPoint - current.PhyPoint).Length;
  1480. if (GeoFeature.Points.Count < 3)
  1481. {
  1482. _isSmartMove = false;
  1483. }
  1484. if (length > autoSnapThreshold * 2.0 && !_isSmartMove)
  1485. {
  1486. _isSmartMove = true;
  1487. }
  1488. // User clear points if GeoFeature.ActivePoint== current.LogicPoint, so the trace shouldn't be smart closed.
  1489. if (length < autoSnapThreshold && _isSmartMove && !GeoFeature.ActivePoint.AlmostEquals(current.LogicPoint))
  1490. {
  1491. IsClosed = true;
  1492. GeoFeature.IsClosed = true;
  1493. _isSmartMove = false;
  1494. completed = true;
  1495. GeoFeature.SyncStates(x =>
  1496. {
  1497. x.AddPoint(x.Points[0]);
  1498. });
  1499. GeoFeature.Points[0].SynchToMainMonitorScreen(GeoFeature.HostArea);
  1500. break;
  1501. }
  1502. }
  1503. }
  1504. }
  1505. foreach (var point in points.AllRegionPoints)
  1506. {
  1507. var geoFeature = GeoFeature.GetSpecificFeature(point.VisualArea);
  1508. if (geoFeature != null)
  1509. {
  1510. geoFeature.AddPoint(point.LogicPoint);
  1511. geoFeature.ActivePoint = point.LogicPoint;
  1512. }
  1513. }
  1514. break;
  1515. }
  1516. }
  1517. if (GeoFeature != null)
  1518. {
  1519. Calculator.Calculate();
  1520. }
  1521. //Update state
  1522. if (args.Action == PointAction.MouseDown)
  1523. {
  1524. if (State == ItemStates.Waiting || State == ItemStates.Finished)
  1525. {
  1526. State = ItemStates.Running;
  1527. }
  1528. if (State == ItemStates.Running && completed)
  1529. {
  1530. FinishEditing((MultiRegionPointInfo)args);
  1531. }
  1532. }
  1533. if ((args.Action == PointAction.MouseMove || args.Action == PointAction.TouchMove) && IsClosed)
  1534. {
  1535. if (State == ItemStates.Running && completed)
  1536. {
  1537. FinishEditing((MultiRegionPointInfo)args);
  1538. }
  1539. }
  1540. return true;
  1541. }
  1542. return false;
  1543. }
  1544. protected override bool OnExecuteTouch(PointInfo args)
  1545. {
  1546. if (State == ItemStates.Finished)
  1547. {
  1548. switch (args.Action)
  1549. {
  1550. case PointAction.TouchUp:
  1551. case PointAction.TouchMove:
  1552. return false;
  1553. case PointAction.TouchDown:
  1554. HandleMouseDownWhileFinished();
  1555. break;
  1556. }
  1557. }
  1558. if (State == ItemStates.Waiting)
  1559. {
  1560. switch (args.Action)
  1561. {
  1562. case PointAction.TouchUp:
  1563. case PointAction.TouchMove:
  1564. return false;
  1565. case PointAction.TouchDown:
  1566. CaliperExtension.HideCaliper();
  1567. HandleMouseDownWhileWaiting((MultiRegionPointInfo)args, (vertices, refItem, xUnit, yUnit) => new ShellTraceFeature(vertices, refItem, xUnit, yUnit));
  1568. if (!args.PixelPerX.AlmostEquals(0))
  1569. {
  1570. float pixelThreshold = PixelThreshold.AlmostEquals(0) ? 4 : PixelThreshold;
  1571. Threshold = (float)(pixelThreshold / args.PixelPerX);
  1572. }
  1573. IsNewMeasure = true;
  1574. IsCompleted = false;
  1575. StartSyncIgnore();
  1576. State = ItemStates.Running;
  1577. break;
  1578. }
  1579. }
  1580. else if (State == ItemStates.Running)
  1581. {
  1582. var points = (MultiRegionPointInfo)args;
  1583. switch (args.Action)
  1584. {
  1585. case PointAction.TouchUp:
  1586. IsRelocatePoints = false;
  1587. if (!IsIgnore)
  1588. {
  1589. if (!GeoFeature.ReEditing && !IsCompleted)
  1590. {
  1591. if (!GeoFeature.Points[0].AlmostEquals(GeoFeature.Points[GeoFeature.Points.Count / 2]))
  1592. {
  1593. IsCompleted = true;
  1594. }
  1595. }
  1596. }
  1597. IsNewMeasure = false;
  1598. FinishEditingForTouch(points);
  1599. GeoFeature.ReEditing = false;
  1600. break;
  1601. case PointAction.TouchMove:
  1602. if (!IsIgnore)
  1603. {
  1604. if (IsNewMeasure && IsRelocatePoints)
  1605. {
  1606. RelocatePoints(points);
  1607. }
  1608. else
  1609. {
  1610. CaliperExtension.HideCaliper();
  1611. if (!GeoFeature.ReEditing)
  1612. {
  1613. var measureService = ServiceManager.Instance.GetService<IMeasureService>();
  1614. double autoSnapThreshold = measureService.Settings.AutoSnapThreshold;
  1615. if ((IsAutoSnap) && autoSnapThreshold > 0)
  1616. {
  1617. var current = points.AllRegionPoints.FirstOrDefault(x => x.VisualArea == GeoFeature.HostArea);
  1618. if (current != null)
  1619. {
  1620. var length = (GeoFeature.Points[0].PointToMainMonitorScreen(GeoFeature.HostArea) - (current.LogicPoint + ActiveTouchPointVector).PointToMainMonitorScreen(GeoFeature.HostArea)).Length;
  1621. if (GeoFeature.Points.Count < 3)
  1622. {
  1623. IsSmartMove = false;
  1624. }
  1625. if (length > autoSnapThreshold * 2.0 && !IsSmartMove)
  1626. {
  1627. IsSmartMove = true;
  1628. }
  1629. if (length < autoSnapThreshold && IsSmartMove)
  1630. {
  1631. IsCompleted = true;
  1632. IsSmartMove = false;
  1633. GeoFeature.SyncStates(x =>
  1634. {
  1635. x.AddPoint(x.Points[0]);
  1636. });
  1637. FinishEditingForTouch(points);
  1638. return true;
  1639. }
  1640. }
  1641. }
  1642. }
  1643. foreach (var point in points.AllRegionPoints)
  1644. {
  1645. var geoFeature = GeoFeature.GetSpecificFeature(point.VisualArea);
  1646. if (geoFeature != null)
  1647. {
  1648. var tempEndPoint = point.LogicPoint + ActiveTouchPointVector;
  1649. if (!ServiceManager.Instance.GetService<ISystemSettingValues>().GetParameterValue("EnableCrossRegionOperation", false) &&
  1650. !point.ContainerBound.Contains(tempEndPoint))
  1651. {
  1652. return true;
  1653. }
  1654. geoFeature.AddPoint(tempEndPoint);
  1655. geoFeature.ActivePoint = tempEndPoint;
  1656. }
  1657. }
  1658. }
  1659. }
  1660. break;
  1661. case PointAction.TouchEnter:
  1662. case PointAction.TouchDown:
  1663. case PointAction.HoldGesture:
  1664. base.OnExecuteTouch(args);
  1665. break;
  1666. }
  1667. }
  1668. return true;
  1669. }
  1670. internal override MeasuredFeature CreateMeasureFeatureFrom(MeasuredFeature source)
  1671. {
  1672. if (source is ShellTraceFeature feature)
  1673. {
  1674. return new ShellTraceFeature(feature.Points, this, feature.XUnit, feature.YUnit)
  1675. {
  1676. HostArea = feature.HostArea,
  1677. ReferenceArea = feature.ReferenceArea,
  1678. FrameIndex = feature.FrameIndex,
  1679. VisualAreaType = feature.VisualAreaType,
  1680. IsClosed = feature.IsClosed,
  1681. ActivePointIndex = -1,
  1682. };
  1683. }
  1684. return null;
  1685. }
  1686. private void OnShellWidthParamsChanged(object sender, EventArgs e)
  1687. {
  1688. Calculator.Calculate();
  1689. }
  1690. }
  1691. public class URMShellDenMeasure : URMShellMeasure
  1692. {
  1693. public URMShellDenMeasure(ItemMeta meta, IMeasureItem parent = null)
  1694. : base(meta, parent)
  1695. {
  1696. }
  1697. internal static URMShellDenMeasure CreateURMShellDenMeasure(ItemMeta meta, IMeasureItem parent)
  1698. {
  1699. if (meta.BaseType != MeasureTypes.URMShellDenMeasure)
  1700. {
  1701. throw new ArgumentException();
  1702. }
  1703. meta.AddArgs(new MeasureParam(IsAutoSnapKey, "true", DefinitionPriorityEnum.Root));
  1704. var item = new URMShellDenMeasure(meta, parent);
  1705. item.Calculator = new URMShellDenMeasureCal(item);
  1706. return item;
  1707. }
  1708. internal sealed class URMShellDenMeasureCal : Calculator<URMShellDenMeasure>
  1709. {
  1710. public URMShellDenMeasureCal(URMShellDenMeasure item)
  1711. : base(item)
  1712. {
  1713. }
  1714. public URMShellDenMeasureCal()
  1715. {
  1716. }
  1717. protected internal override string[] SupportedOutputKeys
  1718. {
  1719. get
  1720. {
  1721. return new[]
  1722. {
  1723. MeasureTerms.URMDenROI, MeasureTerms.URMDenFractalDim, MeasureTerms.URMDenMax,
  1724. MeasureTerms.URMDenMin, MeasureTerms.URMDenMean, MeasureTerms.URMDenStd, MeasureTerms.Area,
  1725. MeasureTerms.URMDenROIIn, MeasureTerms.URMDenFractalDimIn, MeasureTerms.URMDenMaxIn,
  1726. MeasureTerms.URMDenMinIn, MeasureTerms.URMDenMeanIn, MeasureTerms.URMDenStdIn, MeasureTerms.URMAreaIn,
  1727. MeasureTerms.URMDenROIOut, MeasureTerms.URMDenFractalDimOut, MeasureTerms.URMDenMaxOut,
  1728. MeasureTerms.URMDenMinOut, MeasureTerms.URMDenMeanOut, MeasureTerms.URMDenStdOut, MeasureTerms.URMAreaOut,
  1729. };
  1730. }
  1731. }
  1732. protected override void OnCalculate()
  1733. {
  1734. if (RefItem.State != ItemStates.Finished)
  1735. return;
  1736. PolyLineFeature feature = RefItem.GeoFeature;
  1737. int width = 0;
  1738. int height = 0;
  1739. double UrmPhysicalwidth = 0;
  1740. double UrmPhysicalheight = 0;
  1741. NativeArray srcArray = new NativeArray(0);
  1742. if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
  1743. {
  1744. var dicomvisual = feature.HostArea as ISRDicom;
  1745. bool isSRDen = dicomvisual.isSRDen();
  1746. if (!isSRDen)
  1747. return;
  1748. var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
  1749. ref UrmPhysicalheight);
  1750. //todo 坐标转换
  1751. srcArray.Resize(dicomdate.Length);
  1752. Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
  1753. }
  1754. else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
  1755. {
  1756. var modewithURM = feature.HostArea.Mode as IModeWithURM;
  1757. if (modewithURM.URMStyle != "URM(Den)")
  1758. return;
  1759. var date = modewithURM.UrmArray;
  1760. width = modewithURM.URMImgWidth;
  1761. height = modewithURM.URMImgHeight;
  1762. UrmPhysicalwidth = modewithURM.URMPhyWidth;
  1763. UrmPhysicalheight = modewithURM.URMPhyHeight;
  1764. srcArray.Resize(date.Length);
  1765. Marshal.Copy(date, 0, srcArray.Start, date.Length);
  1766. }
  1767. else
  1768. {
  1769. return;
  1770. }
  1771. if (srcArray.Length != 8 * width * height)
  1772. {
  1773. _delayAction.BeginInvoke();
  1774. return;
  1775. }
  1776. //todo 坐标转换
  1777. double regionwidth = feature.HostArea.ViewPort.Region.Width;
  1778. double regionheight = feature.HostArea.ViewPort.Region.Height;
  1779. var points = RefItem.GeoFeature.Points;
  1780. List<DPoint> ImagePoint = new List<DPoint>();
  1781. for (int i = 0; i < points.Count; i++)
  1782. {
  1783. var point = SRPointTrans.TransPointS2I(points[i], regionwidth, regionheight,
  1784. UrmPhysicalwidth, UrmPhysicalheight, width, height,false);
  1785. if (point.X < 0 || point.X > width || point.X < 0 || point.X > width)
  1786. continue;
  1787. ImagePoint.Add(point);
  1788. }
  1789. if(ImagePoint.Count<3)
  1790. return;
  1791. double pixelscaler = UrmPhysicalwidth / width;
  1792. var urmcal = feature.HostArea.Mode as IURMCal;
  1793. if (urmcal == null)
  1794. return;
  1795. //double ShellWidth = 10;//Todo 这一块需要修改为根据设置的shellwidth来
  1796. var result = urmcal.GetURMShellDenMeasureResult(srcArray.Start, width, height, ImagePoint, RefItem.ShellWidth.Value/10,
  1797. pixelscaler, out var outshellPoints); //Todo OutShellPoint调用TransPointI2S转换为逻辑坐标用于绘制
  1798. var transpoints = new List<DPoint>();
  1799. foreach (var point in outshellPoints)
  1800. {
  1801. var transpoint = SRPointTrans.TransPointI2S(point, regionwidth, regionheight,
  1802. UrmPhysicalwidth, UrmPhysicalheight, width, height);
  1803. transpoints.Add(transpoint);
  1804. }
  1805. UpdateGeometry(transpoints);
  1806. foreach (var outputItem in Outputs)
  1807. {
  1808. outputItem.UpdateDescription(outputItem.Name);
  1809. if (string.Equals(outputItem.Name, MeasureTerms.URMDenROI))
  1810. {
  1811. feature.UpdateValue(outputItem, RoundValue(result.RoiDen * 100, outputItem), Unit.percent);
  1812. }
  1813. else if (string.Equals(outputItem.Name, MeasureTerms.URMDenFractalDim))
  1814. {
  1815. feature.UpdateValue(outputItem, RoundValue(result.RoiFractalDim, outputItem), Unit.None);
  1816. }
  1817. else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMax))
  1818. {
  1819. feature.UpdateValue(outputItem, RoundValue(result.MaxDensity, outputItem), Unit.None);
  1820. }
  1821. else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMin))
  1822. {
  1823. feature.UpdateValue(outputItem, RoundValue(result.MinDensity, outputItem), Unit.None);
  1824. }
  1825. else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMean))
  1826. {
  1827. feature.UpdateValue(outputItem, RoundValue(result.MeanDensity, outputItem), Unit.None);
  1828. }
  1829. else if (string.Equals(outputItem.Name, MeasureTerms.URMDenStd))
  1830. {
  1831. feature.UpdateValue(outputItem, RoundValue(Math.Sqrt(result.VarianceDensity), outputItem), Unit.None);
  1832. }
  1833. else if (string.Equals(outputItem.Name, MeasureTerms.Area))
  1834. {
  1835. feature.UpdateValue(outputItem, RoundValue(result.RoiArea, outputItem), Unit.cm2);
  1836. }
  1837. else if (string.Equals(outputItem.Name, MeasureTerms.URMDenROIIn))
  1838. {
  1839. feature.UpdateValue(outputItem, RoundValue(result.InRoiDen * 100, outputItem), Unit.percent);
  1840. }
  1841. else if (string.Equals(outputItem.Name, MeasureTerms.URMDenFractalDimIn))
  1842. {
  1843. feature.UpdateValue(outputItem, RoundValue(result.InRoiFractalDim, outputItem), Unit.None);
  1844. }
  1845. else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMaxIn))
  1846. {
  1847. feature.UpdateValue(outputItem, RoundValue(result.InMaxDensity, outputItem), Unit.None);
  1848. }
  1849. else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMinIn))
  1850. {
  1851. feature.UpdateValue(outputItem, RoundValue(result.InMinDensity, outputItem), Unit.None);
  1852. }
  1853. else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMeanIn))
  1854. {
  1855. feature.UpdateValue(outputItem, RoundValue(result.InMeanDensity, outputItem), Unit.None);
  1856. }
  1857. else if (string.Equals(outputItem.Name, MeasureTerms.URMDenStdIn))
  1858. {
  1859. feature.UpdateValue(outputItem, RoundValue(Math.Sqrt(result.InVarianceDensity), outputItem), Unit.None);
  1860. }
  1861. else if (string.Equals(outputItem.Name, MeasureTerms.URMAreaIn))
  1862. {
  1863. feature.UpdateValue(outputItem, RoundValue(result.InRoiArea, outputItem), Unit.cm2);
  1864. }
  1865. else if (string.Equals(outputItem.Name, MeasureTerms.URMDenROIOut))
  1866. {
  1867. feature.UpdateValue(outputItem, RoundValue(result.OutRoiDen * 100, outputItem), Unit.percent);
  1868. }
  1869. else if (string.Equals(outputItem.Name, MeasureTerms.URMDenFractalDimOut))
  1870. {
  1871. feature.UpdateValue(outputItem, RoundValue(result.OutRoiFractalDim, outputItem), Unit.None);
  1872. }
  1873. else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMaxOut))
  1874. {
  1875. feature.UpdateValue(outputItem, RoundValue(result.OutMaxDensity, outputItem), Unit.None);
  1876. }
  1877. else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMinOut))
  1878. {
  1879. feature.UpdateValue(outputItem, RoundValue(result.OutMinDensity, outputItem), Unit.None);
  1880. }
  1881. else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMeanOut))
  1882. {
  1883. feature.UpdateValue(outputItem, RoundValue(result.OutMeanDensity, outputItem), Unit.None);
  1884. }
  1885. else if (string.Equals(outputItem.Name, MeasureTerms.URMDenStdOut))
  1886. {
  1887. feature.UpdateValue(outputItem, RoundValue(Math.Sqrt(result.OutVarianceDensity), outputItem), Unit.None);
  1888. }
  1889. else if (string.Equals(outputItem.Name, MeasureTerms.URMAreaOut))
  1890. {
  1891. feature.UpdateValue(outputItem, RoundValue(result.OutRoiArea, outputItem), Unit.cm2);
  1892. }
  1893. }
  1894. }
  1895. protected void UpdateGeometry(List<DPoint> outResult)
  1896. {
  1897. var geometry = new TraceLineFeature(outResult, RefItem, RefItem.GeoFeature.XUnit,
  1898. RefItem.GeoFeature.YUnit, false)
  1899. {
  1900. IsClosed = true,
  1901. };
  1902. if (RefItem.GeoFeature is ShellTraceFeature feature)
  1903. {
  1904. feature.UpdateChildFeatures(new List<GeometryFeature> { geometry });
  1905. }
  1906. }
  1907. }
  1908. }
  1909. public class URMShellFractalDim: URMShellMeasure
  1910. {
  1911. public URMShellFractalDim(ItemMeta meta, IMeasureItem parent = null)
  1912. : base(meta, parent)
  1913. {
  1914. }
  1915. internal static URMShellFractalDim CreateURMShellFractalDim(ItemMeta meta, IMeasureItem parent)
  1916. {
  1917. if (meta.BaseType != MeasureTypes.URMShellFractalDim)
  1918. {
  1919. throw new ArgumentException();
  1920. }
  1921. meta.AddArgs(new MeasureParam(IsAutoSnapKey, "true", DefinitionPriorityEnum.Root));
  1922. var item = new URMShellFractalDim(meta, parent);
  1923. item.Calculator = new URMShellFractalDimCal(item);
  1924. return item;
  1925. }
  1926. internal sealed class URMShellFractalDimCal : Calculator<URMShellFractalDim>
  1927. {
  1928. public URMShellFractalDimCal(URMShellFractalDim item)
  1929. : base(item)
  1930. {
  1931. }
  1932. public URMShellFractalDimCal()
  1933. {
  1934. }
  1935. protected internal override string[] SupportedOutputKeys
  1936. {
  1937. get
  1938. {
  1939. return new[]
  1940. {
  1941. MeasureTerms.URMDenFractalDim,
  1942. };
  1943. }
  1944. }
  1945. protected override void OnCalculate()
  1946. {
  1947. if (RefItem.State != ItemStates.Finished)
  1948. return;
  1949. PolyLineFeature feature = RefItem.GeoFeature;
  1950. int width = 0;
  1951. int height = 0;
  1952. double UrmPhysicalwidth = 0;
  1953. double UrmPhysicalheight = 0;
  1954. NativeArray srcArray = new NativeArray(0);
  1955. if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
  1956. {
  1957. var dicomvisual = feature.HostArea as ISRDicom;
  1958. bool isSRDen = dicomvisual.isSRDen();
  1959. if (!isSRDen)
  1960. return;
  1961. var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
  1962. ref UrmPhysicalheight);
  1963. //todo 坐标转换
  1964. srcArray.Resize(dicomdate.Length);
  1965. Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
  1966. }
  1967. else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
  1968. {
  1969. var modewithURM = feature.HostArea.Mode as IModeWithURM;
  1970. if (modewithURM.URMStyle != "URM(Den)")
  1971. return;
  1972. var date = modewithURM.UrmArray;
  1973. width = modewithURM.URMImgWidth;
  1974. height = modewithURM.URMImgHeight;
  1975. UrmPhysicalwidth = modewithURM.URMPhyWidth;
  1976. UrmPhysicalheight = modewithURM.URMPhyHeight;
  1977. srcArray.Resize(date.Length);
  1978. Marshal.Copy(date, 0, srcArray.Start, date.Length);
  1979. }
  1980. else
  1981. {
  1982. return;
  1983. }
  1984. if (srcArray.Length != 8 * width * height)
  1985. {
  1986. _delayAction.BeginInvoke();
  1987. return;
  1988. }
  1989. //todo 坐标转换
  1990. double regionwidth = feature.HostArea.ViewPort.Region.Width;
  1991. double regionheight = feature.HostArea.ViewPort.Region.Height;
  1992. var points = RefItem.GeoFeature.Points;
  1993. List<DPoint> ImagePoint = new List<DPoint>();
  1994. for (int i = 0; i < points.Count; i++)
  1995. {
  1996. var point = SRPointTrans.TransPointS2I(points[i], regionwidth, regionheight,
  1997. UrmPhysicalwidth, UrmPhysicalheight, width, height,false);
  1998. if (point.X < 0 || point.X > width || point.X < 0 || point.X > width)
  1999. continue;
  2000. ImagePoint.Add(point);
  2001. }
  2002. if (ImagePoint.Count < 3)
  2003. return;
  2004. double pixelscaler = UrmPhysicalwidth / width;
  2005. var urmcal = feature.HostArea.Mode as IURMCal;
  2006. if (urmcal == null)
  2007. return;
  2008. var result = urmcal.GetURMShellDenMeasureResult(srcArray.Start, width, height, ImagePoint, RefItem.ShellWidth.Value / 10,
  2009. pixelscaler, out var outshellPoints); //Todo OutShellPoint调用TransPointI2S转换为逻辑坐标用于绘制
  2010. var transpoints = new List<DPoint>();
  2011. foreach (var point in outshellPoints)
  2012. {
  2013. var transpoint = SRPointTrans.TransPointI2S(point, regionwidth, regionheight,
  2014. UrmPhysicalwidth, UrmPhysicalheight, width, height);
  2015. transpoints.Add(transpoint);
  2016. }
  2017. UpdateGeometry(transpoints);
  2018. Outputs[0].UpdateDescription(Outputs[0].Name);
  2019. feature.UpdateValue(Outputs[0], RoundValue(result.RoiFractalDim, GetResultDigits(PrimaryOutput)), Unit.None);
  2020. }
  2021. protected void UpdateGeometry(List<DPoint> outResult)
  2022. {
  2023. var geometry = new TraceLineFeature(outResult, RefItem, RefItem.GeoFeature.XUnit,
  2024. RefItem.GeoFeature.YUnit, false)
  2025. {
  2026. IsClosed = true,
  2027. };
  2028. if (RefItem.GeoFeature is ShellTraceFeature feature)
  2029. {
  2030. feature.UpdateChildFeatures(new List<GeometryFeature> { geometry });
  2031. }
  2032. }
  2033. }
  2034. }
  2035. public class URMShellDensity : URMShellMeasure
  2036. {
  2037. public URMShellDensity(ItemMeta meta, IMeasureItem parent = null)
  2038. : base(meta, parent)
  2039. {
  2040. }
  2041. internal static URMShellDensity CreateURMShellDensity(ItemMeta meta, IMeasureItem parent)
  2042. {
  2043. if (meta.BaseType != MeasureTypes.URMShellDensity)
  2044. {
  2045. throw new ArgumentException();
  2046. }
  2047. meta.AddArgs(new MeasureParam(IsAutoSnapKey, "true", DefinitionPriorityEnum.Root));
  2048. var item = new URMShellDensity(meta, parent);
  2049. item.Calculator = new URMShellDensityCal(item);
  2050. return item;
  2051. }
  2052. internal sealed class URMShellDensityCal : Calculator<URMShellDensity>
  2053. {
  2054. public URMShellDensityCal(URMShellDensity item)
  2055. : base(item)
  2056. {
  2057. }
  2058. public URMShellDensityCal()
  2059. {
  2060. }
  2061. protected internal override string[] SupportedOutputKeys
  2062. {
  2063. get
  2064. {
  2065. return new[]
  2066. {
  2067. MeasureTerms.URMDenROI,
  2068. };
  2069. }
  2070. }
  2071. protected override void OnCalculate()
  2072. {
  2073. if (RefItem.State != ItemStates.Finished)
  2074. return;
  2075. PolyLineFeature feature = RefItem.GeoFeature;
  2076. int width = 0;
  2077. int height = 0;
  2078. double UrmPhysicalwidth = 0;
  2079. double UrmPhysicalheight = 0;
  2080. NativeArray srcArray = new NativeArray(0);
  2081. if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
  2082. {
  2083. var dicomvisual = feature.HostArea as ISRDicom;
  2084. bool isSRDen = dicomvisual.isSRDen();
  2085. if (!isSRDen)
  2086. return;
  2087. var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
  2088. ref UrmPhysicalheight);
  2089. //todo 坐标转换
  2090. srcArray.Resize(dicomdate.Length);
  2091. Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
  2092. }
  2093. else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
  2094. {
  2095. var modewithURM = feature.HostArea.Mode as IModeWithURM;
  2096. if (modewithURM.URMStyle != "URM(Den)")
  2097. return;
  2098. var date = modewithURM.UrmArray;
  2099. width = modewithURM.URMImgWidth;
  2100. height = modewithURM.URMImgHeight;
  2101. UrmPhysicalwidth = modewithURM.URMPhyWidth;
  2102. UrmPhysicalheight = modewithURM.URMPhyHeight;
  2103. srcArray.Resize(date.Length);
  2104. Marshal.Copy(date, 0, srcArray.Start, date.Length);
  2105. }
  2106. else
  2107. {
  2108. return;
  2109. }
  2110. if (srcArray.Length != 8 * width * height)
  2111. {
  2112. _delayAction.BeginInvoke();
  2113. return;
  2114. }
  2115. //todo 坐标转换
  2116. double regionwidth = feature.HostArea.ViewPort.Region.Width;
  2117. double regionheight = feature.HostArea.ViewPort.Region.Height;
  2118. var points = RefItem.GeoFeature.Points;
  2119. List<DPoint> ImagePoint = new List<DPoint>();
  2120. for (int i = 0; i < points.Count; i++)
  2121. {
  2122. var point = SRPointTrans.TransPointS2I(points[i], regionwidth, regionheight,
  2123. UrmPhysicalwidth, UrmPhysicalheight, width, height,false);
  2124. if (point.X < 0 || point.X > width || point.X < 0 || point.X > width)
  2125. continue;
  2126. ImagePoint.Add(point);
  2127. }
  2128. if (ImagePoint.Count < 3)
  2129. return;
  2130. double pixelscaler = UrmPhysicalwidth / width;
  2131. var urmcal = feature.HostArea.Mode as IURMCal;
  2132. if (urmcal == null)
  2133. return;
  2134. var result = urmcal.GetURMShellDenMeasureResult(srcArray.Start, width, height, ImagePoint, RefItem.ShellWidth.Value / 10,
  2135. pixelscaler, out var outshellPoints); //Todo OutShellPoint调用TransPointI2S转换为逻辑坐标用于绘制
  2136. var transpoints = new List<DPoint>();
  2137. foreach (var point in outshellPoints)
  2138. {
  2139. var transpoint = SRPointTrans.TransPointI2S(point, regionwidth, regionheight,
  2140. UrmPhysicalwidth, UrmPhysicalheight, width, height);
  2141. transpoints.Add(transpoint);
  2142. }
  2143. UpdateGeometry(transpoints);
  2144. Outputs[0].UpdateDescription(Outputs[0].Name);
  2145. feature.UpdateValue(Outputs[0], RoundValue(result.RoiDen * 100, GetResultDigits(PrimaryOutput)), Unit.percent);
  2146. }
  2147. protected void UpdateGeometry(List<DPoint> outResult)
  2148. {
  2149. var geometry = new TraceLineFeature(outResult, RefItem, RefItem.GeoFeature.XUnit,
  2150. RefItem.GeoFeature.YUnit, false)
  2151. {
  2152. IsClosed = true,
  2153. };
  2154. if (RefItem.GeoFeature is ShellTraceFeature feature)
  2155. {
  2156. feature.UpdateChildFeatures(new List<GeometryFeature> { geometry });
  2157. }
  2158. }
  2159. }
  2160. }
  2161. internal class URMShellVelMeasure : URMShellMeasure
  2162. {
  2163. public URMShellVelMeasure(ItemMeta meta, IMeasureItem parent = null)
  2164. : base(meta, parent)
  2165. {
  2166. }
  2167. internal static URMShellVelMeasure CreateURMShellVelMeasure(ItemMeta meta, IMeasureItem parent)
  2168. {
  2169. if (meta.BaseType != MeasureTypes.URMShellVelMeasure)
  2170. {
  2171. throw new ArgumentException();
  2172. }
  2173. meta.AddArgs(new MeasureParam(IsAutoSnapKey, "true", DefinitionPriorityEnum.Root));
  2174. var item = new URMShellVelMeasure(meta, parent);
  2175. item.Calculator = new URMShellVelMeasureCal(item);
  2176. return item;
  2177. }
  2178. internal sealed class URMShellVelMeasureCal : Calculator<URMShellVelMeasure>
  2179. {
  2180. public URMShellVelMeasureCal(URMShellVelMeasure item)
  2181. : base(item)
  2182. {
  2183. }
  2184. public URMShellVelMeasureCal()
  2185. {
  2186. }
  2187. protected internal override string[] SupportedOutputKeys
  2188. {
  2189. get
  2190. {
  2191. return new[]
  2192. {
  2193. MeasureTerms.URMVelMax, MeasureTerms.URMVelMin, MeasureTerms.URMVelMean, MeasureTerms.URMVelStd, MeasureTerms.Area,
  2194. MeasureTerms.URMVelMaxIn, MeasureTerms.URMVelMinIn, MeasureTerms.URMVelMeanIn, MeasureTerms.URMVelStdIn, MeasureTerms.URMAreaIn,
  2195. MeasureTerms.URMVelMaxOut, MeasureTerms.URMVelMinOut, MeasureTerms.URMVelMeanOut, MeasureTerms.URMVelStdOut, MeasureTerms.URMAreaOut,
  2196. };
  2197. }
  2198. }
  2199. protected override void OnCalculate()
  2200. {
  2201. if (RefItem.State != ItemStates.Finished)
  2202. return;
  2203. PolyLineFeature feature = RefItem.GeoFeature;
  2204. int width = 0;
  2205. int height = 0;
  2206. double UrmPhysicalwidth = 0;
  2207. double UrmPhysicalheight = 0;
  2208. double UrmMinVel = 0;
  2209. NativeArray srcArray = new NativeArray(0);
  2210. if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
  2211. {
  2212. var dicomvisual = feature.HostArea as ISRDicom;
  2213. bool isSRVel = dicomvisual.isSRVel();
  2214. if (!isSRVel)
  2215. return;
  2216. var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
  2217. ref UrmPhysicalheight);
  2218. //todo 坐标转换
  2219. srcArray.Resize(dicomdate.Length);
  2220. Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
  2221. UrmMinVel = dicomvisual.GetSRMinVel();
  2222. }
  2223. else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
  2224. {
  2225. var modewithURM = feature.HostArea.Mode as IModeWithURM;
  2226. if (modewithURM.URMStyle != "URM(Vel)")
  2227. return;
  2228. var date = modewithURM.UrmArray;
  2229. width = modewithURM.URMImgWidth;
  2230. height = modewithURM.URMImgHeight;
  2231. UrmPhysicalwidth = modewithURM.URMPhyWidth;
  2232. UrmPhysicalheight = modewithURM.URMPhyHeight;
  2233. UrmMinVel = modewithURM.URMMinVel;
  2234. srcArray.Resize(date.Length);
  2235. Marshal.Copy(date, 0, srcArray.Start, date.Length);
  2236. }
  2237. else
  2238. {
  2239. return;
  2240. }
  2241. //todo 坐标转换
  2242. double regionwidth = feature.HostArea.ViewPort.Region.Width;
  2243. double regionheight = feature.HostArea.ViewPort.Region.Height;
  2244. var points = RefItem.GeoFeature.Points;
  2245. List<DPoint> ImagePoint = new List<DPoint>();
  2246. for (int i = 0; i < points.Count; i++)
  2247. {
  2248. var point = SRPointTrans.TransPointS2I(points[i], regionwidth, regionheight,
  2249. UrmPhysicalwidth, UrmPhysicalheight, width, height,false);
  2250. if (point.X < 0 || point.X > width || point.X < 0 || point.X > width)
  2251. continue;
  2252. ImagePoint.Add(point);
  2253. }
  2254. if(ImagePoint.Count<3)
  2255. return;
  2256. double pixelscaler = UrmPhysicalwidth / width;
  2257. var urmcal = feature.HostArea.Mode as IURMCal;
  2258. if (urmcal == null)
  2259. return;
  2260. var result = urmcal.GetURMShellVelMeasureResult(srcArray.Start, width, height, ImagePoint, RefItem.ShellWidth.Value/10,
  2261. pixelscaler, out var outshellPoints); //Todo OutShellPoint调用TransPointI2S转换为逻辑坐标用于绘制
  2262. var transpoints = new List<DPoint>();
  2263. foreach (var point in outshellPoints)
  2264. {
  2265. var transpoint = SRPointTrans.TransPointI2S(point, regionwidth, regionheight,
  2266. UrmPhysicalwidth, UrmPhysicalheight, width, height);
  2267. transpoints.Add(transpoint);
  2268. }
  2269. UpdateGeometry(transpoints);
  2270. foreach (var outputItem in Outputs)
  2271. {
  2272. outputItem.UpdateDescription(outputItem.Name);
  2273. if (string.Equals(outputItem.Name, MeasureTerms.URMVelMax))
  2274. {
  2275. feature.UpdateValue(outputItem, RoundValue(result.MaxVel + UrmMinVel, outputItem), Unit.mms);
  2276. }
  2277. else if (string.Equals(outputItem.Name, MeasureTerms.URMVelMin))
  2278. {
  2279. feature.UpdateValue(outputItem, RoundValue(result.MinVel + UrmMinVel, outputItem), Unit.mms);
  2280. }
  2281. else if (string.Equals(outputItem.Name, MeasureTerms.URMVelMean))
  2282. {
  2283. feature.UpdateValue(outputItem, RoundValue(result.MeanVel + UrmMinVel, outputItem), Unit.mms);
  2284. }
  2285. else if (string.Equals(outputItem.Name, MeasureTerms.URMVelStd))
  2286. {
  2287. feature.UpdateValue(outputItem, RoundValue(Math.Sqrt(result.VarianceVel), outputItem), Unit.mms);
  2288. }
  2289. else if (string.Equals(outputItem.Name, MeasureTerms.Area))
  2290. {
  2291. feature.UpdateValue(outputItem, RoundValue(result.RoiArea, outputItem), Unit.cm2);
  2292. }
  2293. else if (string.Equals(outputItem.Name, MeasureTerms.URMVelMaxIn))
  2294. {
  2295. feature.UpdateValue(outputItem, RoundValue(result.InMaxVel + UrmMinVel, outputItem), Unit.mms);
  2296. }
  2297. else if (string.Equals(outputItem.Name, MeasureTerms.URMVelMinIn))
  2298. {
  2299. feature.UpdateValue(outputItem, RoundValue(result.InMinVel + UrmMinVel, outputItem), Unit.mms);
  2300. }
  2301. else if (string.Equals(outputItem.Name, MeasureTerms.URMVelMeanIn))
  2302. {
  2303. feature.UpdateValue(outputItem, RoundValue(result.InMeanVel + UrmMinVel, outputItem), Unit.mms);
  2304. }
  2305. else if (string.Equals(outputItem.Name, MeasureTerms.URMVelStdIn))
  2306. {
  2307. feature.UpdateValue(outputItem, RoundValue(Math.Sqrt(result.InVarianceVel), outputItem), Unit.mms);
  2308. }
  2309. else if (string.Equals(outputItem.Name, MeasureTerms.URMAreaIn))
  2310. {
  2311. feature.UpdateValue(outputItem, RoundValue(result.InRoiArea, outputItem), Unit.cm2);
  2312. }
  2313. else if (string.Equals(outputItem.Name, MeasureTerms.URMVelMaxOut))
  2314. {
  2315. feature.UpdateValue(outputItem, RoundValue(result.OutMaxVel + UrmMinVel, outputItem), Unit.mms);
  2316. }
  2317. else if (string.Equals(outputItem.Name, MeasureTerms.URMVelMinOut))
  2318. {
  2319. feature.UpdateValue(outputItem, RoundValue(result.OutMinVel + UrmMinVel, outputItem), Unit.mms);
  2320. }
  2321. else if (string.Equals(outputItem.Name, MeasureTerms.URMVelMeanOut))
  2322. {
  2323. feature.UpdateValue(outputItem, RoundValue(result.OutMeanVel + UrmMinVel, outputItem), Unit.mms);
  2324. }
  2325. else if (string.Equals(outputItem.Name, MeasureTerms.URMVelStdOut))
  2326. {
  2327. feature.UpdateValue(outputItem, RoundValue(Math.Sqrt(result.OutVarianceVel), outputItem), Unit.mms);
  2328. }
  2329. else if (string.Equals(outputItem.Name, MeasureTerms.URMAreaOut))
  2330. {
  2331. feature.UpdateValue(outputItem, RoundValue(result.OutRoiArea, outputItem), Unit.cm2);
  2332. }
  2333. }
  2334. }
  2335. private void UpdateGeometry(List<DPoint> outResult)
  2336. {
  2337. //if (outResult.ResultFlag)
  2338. {
  2339. //var resultPoints = outResult.OuterShellPoints;
  2340. // var transformPoints = new List<DPoint>();
  2341. // foreach (var point in outResult)
  2342. // {
  2343. // transformPoints.Add(RefItem.GeoFeature.HostArea.ViewPort.Convert(point));
  2344. // }
  2345. var geometry = new TraceLineFeature(outResult, RefItem, RefItem.GeoFeature.XUnit,
  2346. RefItem.GeoFeature.YUnit, false)
  2347. {
  2348. IsClosed = true,
  2349. };
  2350. if (RefItem.GeoFeature is ShellTraceFeature feature)
  2351. {
  2352. feature.UpdateChildFeatures(new List<GeometryFeature> { geometry });
  2353. }
  2354. }
  2355. }
  2356. }
  2357. }
  2358. internal class SRTraceMeasure : Trace
  2359. {
  2360. private bool calflag = false;
  2361. public SRTraceMeasure(ItemMeta meta, IMeasureItem parent = null)
  2362. : base(meta, parent)
  2363. {
  2364. }
  2365. internal static SRTraceMeasure CreateSRTraceMeasure(ItemMeta meta, IMeasureItem parent)
  2366. {
  2367. if (meta == null || meta.BaseType != MeasureTypes.SRTraceDensity)
  2368. {
  2369. throw new ArgumentException();
  2370. }
  2371. meta.AddArgs(new MeasureParam(IsAutoSnapKey, "true", DefinitionPriorityEnum.Root));
  2372. var SRTrace = new SRTraceMeasure(meta, parent);
  2373. SRTrace.Calculator = new SRTraceCal(SRTrace);
  2374. return SRTrace;
  2375. }
  2376. public override void DownloadValueFromPreviousItem()
  2377. {
  2378. }
  2379. protected override bool OnExecute(PointInfo args)
  2380. {
  2381. var cal = Calculator as SRTraceCal;
  2382. if (args.VisualArea is ISRDicom)
  2383. {
  2384. var dicomvisual = args.VisualArea as ISRDicom;
  2385. bool isSRDen = dicomvisual.isSRDen();
  2386. if (args.VisualArea.Mode == null || !isSRDen)
  2387. {
  2388. return false;
  2389. }
  2390. }
  2391. else
  2392. {
  2393. var modewithurm = args.VisualArea.Mode as IModeWithURM;
  2394. if (modewithurm == null || modewithurm?.URMStyle != "URM(Den)")
  2395. return false;
  2396. }
  2397. calflag = false;
  2398. cal.calflag = false;
  2399. var preState = State;
  2400. var result = base.OnExecute(args);
  2401. if (result && preState == ItemStates.Running && State == ItemStates.Finished)
  2402. {
  2403. calflag = true;
  2404. cal.calflag = true;
  2405. }
  2406. return result;
  2407. }
  2408. protected override void OnExecuted(PointInfo args)
  2409. {
  2410. if (GeoFeature != null && Calculator != null && calflag)
  2411. {
  2412. Calculator.Calculate();
  2413. }
  2414. }
  2415. internal sealed class SRTraceCal : Calculator<SRTraceMeasure>
  2416. {
  2417. public bool calflag = false;
  2418. public SRTraceCal(SRTraceMeasure item)
  2419. : base(item)
  2420. {
  2421. }
  2422. public SRTraceCal()
  2423. {
  2424. }
  2425. protected internal override string[] SupportedOutputKeys
  2426. {
  2427. get
  2428. {
  2429. return new[]
  2430. {
  2431. MeasureTerms.URMDenROI
  2432. };
  2433. }
  2434. }
  2435. protected override void OnCalculate()
  2436. {
  2437. if (!calflag)
  2438. return;
  2439. PolyLineFeature feature = RefItem.GeoFeature;
  2440. int width = 0;
  2441. int height = 0;
  2442. double UrmPhysicalwidth = 0;
  2443. double UrmPhysicalheight = 0;
  2444. NativeArray srcArray = new NativeArray(0);
  2445. if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
  2446. {
  2447. var dicomvisual = feature.HostArea as ISRDicom;
  2448. bool isSRDen = dicomvisual.isSRDen();
  2449. if (!isSRDen)
  2450. return;
  2451. var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
  2452. ref UrmPhysicalheight);
  2453. //todo 坐标转换
  2454. srcArray.Resize(dicomdate.Length);
  2455. Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
  2456. }
  2457. else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
  2458. {
  2459. var modewithURM = feature.HostArea.Mode as IModeWithURM;
  2460. if (modewithURM.URMStyle != "URM(Den)")
  2461. return;
  2462. var date = modewithURM.UrmArray;
  2463. width = modewithURM.URMImgWidth;
  2464. height = modewithURM.URMImgHeight;
  2465. UrmPhysicalwidth = modewithURM.URMPhyWidth;
  2466. UrmPhysicalheight = modewithURM.URMPhyHeight;
  2467. srcArray.Resize(date.Length);
  2468. Marshal.Copy(date, 0, srcArray.Start, date.Length);
  2469. }
  2470. else
  2471. {
  2472. return;
  2473. }
  2474. if (srcArray.Length != 8 * width * height)
  2475. {
  2476. _delayAction.BeginInvoke();
  2477. return;
  2478. }
  2479. //todo 坐标转换
  2480. double regionwidth = feature.HostArea.ViewPort.Region.Width;
  2481. double regionheight = feature.HostArea.ViewPort.Region.Height;
  2482. var points = RefItem.GeoFeature.Points;
  2483. List<DPoint> ImagePoint=new List<DPoint>();
  2484. for (int i = 0; i < points.Count; i++)
  2485. {
  2486. var point= SRPointTrans.TransPointS2I(points[i], regionwidth, regionheight,
  2487. UrmPhysicalwidth, UrmPhysicalheight, width, height);
  2488. if (point.X < 0 || point.X > width || point.X < 0 || point.X > width)
  2489. continue;
  2490. ImagePoint.Add(point);
  2491. }
  2492. int outPointsNum = 0;
  2493. var urmcal = feature.HostArea.Mode as IURMCal;
  2494. if (urmcal == null|| ImagePoint.Count<3)
  2495. return;
  2496. double roivel = urmcal.GetSRTraceVel(srcArray.Start, width, height, ImagePoint);
  2497. Outputs[0].UpdateDescription(Outputs[0].Name);
  2498. feature.UpdateValue(Outputs[0], RoundValue(roivel * 100, GetResultDigits(PrimaryOutput)), Unit.percent);
  2499. }
  2500. }
  2501. }
  2502. internal class SRROIFractalDimMeasure : Rect
  2503. {
  2504. private bool calflag = false;
  2505. public SRROIFractalDimMeasure(ItemMeta meta, IMeasureItem parent = null)
  2506. : base(meta, parent)
  2507. {
  2508. }
  2509. internal static SRROIFractalDimMeasure CreateSRROIFractalDimMeasure(ItemMeta meta, IMeasureItem parent)
  2510. {
  2511. if (meta == null || meta.BaseType != MeasureTypes.SRROIFractalDim)
  2512. {
  2513. throw new ArgumentException();
  2514. }
  2515. var SRROIFractalDim = new SRROIFractalDimMeasure(meta, parent);
  2516. SRROIFractalDim.Calculator = new SRROIFractalDimCal(SRROIFractalDim);
  2517. return SRROIFractalDim;
  2518. }
  2519. public override void DownloadValueFromPreviousItem()
  2520. {
  2521. }
  2522. protected override bool OnExecute(PointInfo args)
  2523. {
  2524. var cal = Calculator as SRROIFractalDimCal;
  2525. if (args.VisualArea is ISRDicom)
  2526. {
  2527. var dicomvisual = args.VisualArea as ISRDicom;
  2528. bool isSRDen = dicomvisual.isSRDen();
  2529. if (args.VisualArea.Mode == null || !isSRDen)
  2530. {
  2531. return false;
  2532. }
  2533. }
  2534. else
  2535. {
  2536. var modewithurm = args.VisualArea.Mode as IModeWithURM;
  2537. if (modewithurm == null || modewithurm?.URMStyle != "URM(Den)")
  2538. return false;
  2539. }
  2540. calflag = false;
  2541. cal.calfalg = false;
  2542. var preState = State;
  2543. var result = base.OnExecute(args);
  2544. if (result && preState == ItemStates.Running && State == ItemStates.Finished)
  2545. {
  2546. calflag = true;
  2547. cal.calfalg = true;
  2548. }
  2549. return result;
  2550. }
  2551. protected override void OnExecuted(PointInfo args)
  2552. {
  2553. if (GeoFeature != null && Calculator != null && calflag)
  2554. {
  2555. Calculator.Calculate();
  2556. }
  2557. }
  2558. internal sealed class SRROIFractalDimCal : Calculator<SRROIFractalDimMeasure>
  2559. {
  2560. public bool calfalg = false;
  2561. public SRROIFractalDimCal(SRROIFractalDimMeasure item)
  2562. : base(item)
  2563. {
  2564. }
  2565. public SRROIFractalDimCal()
  2566. {
  2567. }
  2568. protected internal override string[] SupportedOutputKeys
  2569. {
  2570. get
  2571. {
  2572. return new[]
  2573. {
  2574. MeasureTerms.URMDenFractalDim
  2575. };
  2576. }
  2577. }
  2578. protected override void OnCalculate()
  2579. {
  2580. if(!calfalg)
  2581. return;
  2582. RectFeature feature = RefItem.GeoFeature;
  2583. int width = 0;
  2584. int height = 0;
  2585. double UrmPhysicalwidth = 0;
  2586. double UrmPhysicalheight = 0;
  2587. NativeArray srcArray = new NativeArray(0);
  2588. if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
  2589. {
  2590. var dicomvisual = feature.HostArea as ISRDicom;
  2591. bool isSRDen = dicomvisual.isSRDen();
  2592. if (!isSRDen)
  2593. return;
  2594. var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
  2595. ref UrmPhysicalheight);
  2596. //todo 坐标转换
  2597. srcArray.Resize(dicomdate.Length);
  2598. Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
  2599. }
  2600. else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
  2601. {
  2602. var modewithURM = feature.HostArea.Mode as IModeWithURM;
  2603. if (modewithURM.URMStyle != "URM(Den)")
  2604. return;
  2605. var date = modewithURM.UrmArray;
  2606. width = modewithURM.URMImgWidth;
  2607. height = modewithURM.URMImgHeight;
  2608. UrmPhysicalwidth = modewithURM.URMPhyWidth;
  2609. UrmPhysicalheight = modewithURM.URMPhyHeight;
  2610. srcArray.Resize(date.Length);
  2611. Marshal.Copy(date, 0, srcArray.Start, date.Length);
  2612. }
  2613. else
  2614. {
  2615. return;
  2616. }
  2617. if (srcArray.Length != 8 * width * height)
  2618. {
  2619. _delayAction.BeginInvoke();
  2620. return;
  2621. }
  2622. //todo 坐标转换
  2623. double regionwidth = feature.HostArea.ViewPort.Region.Width;
  2624. double regionheight = feature.HostArea.ViewPort.Region.Height;
  2625. DPoint startDPoint = SRPointTrans.TransPointS2I(feature.TopLeft, regionwidth, regionheight,
  2626. UrmPhysicalwidth, UrmPhysicalheight, width, height);
  2627. DPoint endDPoint = SRPointTrans.TransPointS2I(feature.BottomRight, regionwidth, regionheight,
  2628. UrmPhysicalwidth, UrmPhysicalheight, width, height);
  2629. if (startDPoint.X < 0 || startDPoint.X > width || endDPoint.X < 0 || endDPoint.X > width
  2630. || startDPoint.Y < 0 || startDPoint.Y > height || endDPoint.Y < 0 || endDPoint.Y > height)
  2631. return;
  2632. int outPointsNum = 0;
  2633. var urmcal = feature.HostArea.Mode as IURMCal;
  2634. if (urmcal == null)
  2635. return;
  2636. double FractalDimvel = urmcal.GetSRRoiFractalDim(srcArray.Start, width, height, startDPoint.X,
  2637. startDPoint.Y, endDPoint.X, endDPoint.Y);
  2638. Outputs[0].UpdateDescription(Outputs[0].Name);
  2639. feature.UpdateValue(Outputs[0], RoundValue(FractalDimvel, GetResultDigits(PrimaryOutput)), Unit.None);
  2640. }
  2641. }
  2642. }
  2643. internal class SRROIVelMeasure : Rect
  2644. {
  2645. private bool calflag = false;
  2646. public SRROIVelMeasure(ItemMeta meta, IMeasureItem parent = null)
  2647. : base(meta, parent)
  2648. {
  2649. }
  2650. internal static SRROIVelMeasure CreateSRROIVelMeasure(ItemMeta meta, IMeasureItem parent)
  2651. {
  2652. if (meta == null || meta.BaseType != MeasureTypes.SRRoiVel)
  2653. {
  2654. throw new ArgumentException();
  2655. }
  2656. var SRROIVel = new SRROIVelMeasure(meta, parent);
  2657. SRROIVel.Calculator = new SRRolVelCal(SRROIVel);
  2658. return SRROIVel;
  2659. }
  2660. public override void DownloadValueFromPreviousItem()
  2661. {
  2662. }
  2663. protected override bool OnExecute(PointInfo args)
  2664. {
  2665. var cal = Calculator as SRRolVelCal;
  2666. if (args.VisualArea is ISRDicom)
  2667. {
  2668. var dicomvisual = args.VisualArea as ISRDicom;
  2669. bool isSrVel = dicomvisual.isSRVel();
  2670. if (args.VisualArea.Mode == null || !isSrVel)
  2671. {
  2672. return false;
  2673. }
  2674. }
  2675. else
  2676. {
  2677. var modewithurm = args.VisualArea.Mode as IModeWithURM;
  2678. if (modewithurm == null || modewithurm?.URMStyle != "URM(Vel)")
  2679. return false;
  2680. }
  2681. calflag = false;
  2682. cal.calfalg = false;
  2683. var preState = State;
  2684. var result = base.OnExecute(args);
  2685. if (result && preState == ItemStates.Running && State == ItemStates.Finished)
  2686. {
  2687. calflag = true;
  2688. cal.calfalg = true;
  2689. }
  2690. return result;
  2691. }
  2692. protected override void OnExecuted(PointInfo args)
  2693. {
  2694. if (GeoFeature != null && Calculator != null && calflag)
  2695. {
  2696. Calculator.Calculate();
  2697. }
  2698. }
  2699. internal sealed class SRRolVelCal : Calculator<SRROIVelMeasure>
  2700. {
  2701. public bool calfalg = false;
  2702. public SRRolVelCal(SRROIVelMeasure item)
  2703. : base(item)
  2704. {
  2705. }
  2706. public SRRolVelCal()
  2707. {
  2708. }
  2709. internal static readonly string SRkey = "SRRoiVel";
  2710. protected internal override string[] SupportedOutputKeys
  2711. {
  2712. get { return new[] { SRkey }; }
  2713. }
  2714. protected override void OnCalculate()
  2715. {
  2716. if (!calfalg)
  2717. return;
  2718. RectFeature feature = RefItem.GeoFeature;
  2719. int width = 0;
  2720. int height = 0;
  2721. double UrmPhysicalwidth = 0;
  2722. double UrmPhysicalheight = 0;
  2723. double UrmMinVel = 0;
  2724. NativeArray srcArray = new NativeArray(0);
  2725. if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
  2726. {
  2727. var dicomvisual = feature.HostArea as ISRDicom;
  2728. bool isSRVel = dicomvisual.isSRVel();
  2729. if (!isSRVel)
  2730. return;
  2731. var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
  2732. ref UrmPhysicalheight);
  2733. //todo 坐标转换
  2734. srcArray.Resize(dicomdate.Length);
  2735. Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
  2736. UrmMinVel = dicomvisual.GetSRMinVel();
  2737. }
  2738. else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
  2739. {
  2740. var modewithURM = feature.HostArea.Mode as IModeWithURM;
  2741. if (modewithURM.URMStyle != "URM(Vel)")
  2742. return;
  2743. var date = modewithURM.UrmArray;
  2744. width = modewithURM.URMImgWidth;
  2745. height = modewithURM.URMImgHeight;
  2746. UrmPhysicalwidth = modewithURM.URMPhyWidth;
  2747. UrmPhysicalheight = modewithURM.URMPhyHeight;
  2748. UrmMinVel = modewithURM.URMMinVel;
  2749. srcArray.Resize(date.Length);
  2750. Marshal.Copy(date, 0, srcArray.Start, date.Length);
  2751. }
  2752. else
  2753. {
  2754. return;
  2755. }
  2756. //todo 坐标转换
  2757. double regionwidth = feature.HostArea.ViewPort.Region.Width;
  2758. double regionheight = feature.HostArea.ViewPort.Region.Height;
  2759. DPoint startDPoint = SRPointTrans.TransPointS2I(feature.TopLeft, regionwidth, regionheight,
  2760. UrmPhysicalwidth, UrmPhysicalheight, width, height);
  2761. DPoint endDPoint = SRPointTrans.TransPointS2I(feature.BottomRight, regionwidth, regionheight,
  2762. UrmPhysicalwidth, UrmPhysicalheight, width, height);
  2763. if (startDPoint.X < 0 || startDPoint.X > width || endDPoint.X < 0 || endDPoint.X > width
  2764. || startDPoint.Y < 0 || startDPoint.Y > height || endDPoint.Y < 0 || endDPoint.Y > height)
  2765. return;
  2766. var urmcal = feature.HostArea.Mode as IURMCal;
  2767. if (urmcal == null)
  2768. return;
  2769. double meanSpeed = urmcal.GetSRRoiSpeed(srcArray.Start, width, height, startDPoint.X,
  2770. startDPoint.Y, endDPoint.X, endDPoint.Y);
  2771. meanSpeed += UrmMinVel;
  2772. feature.UpdateValue(PrimaryOutput, RoundValue(meanSpeed, GetResultDigits(PrimaryOutput)), Unit.mms);
  2773. }
  2774. }
  2775. }
  2776. internal class SRTraceFractalDimMeasure : Trace
  2777. {
  2778. private bool calflag = false;
  2779. public SRTraceFractalDimMeasure(ItemMeta meta, IMeasureItem parent = null)
  2780. : base(meta, parent)
  2781. {
  2782. }
  2783. internal static SRTraceFractalDimMeasure CreateSRTraceFractalDimMeasure(ItemMeta meta, IMeasureItem parent)
  2784. {
  2785. if (meta == null || meta.BaseType != MeasureTypes.SRTraceFractalDim)
  2786. {
  2787. throw new ArgumentException();
  2788. }
  2789. meta.AddArgs(new MeasureParam(IsAutoSnapKey, "true", DefinitionPriorityEnum.Root));
  2790. var SRTraceFractalDim = new SRTraceFractalDimMeasure(meta, parent);
  2791. SRTraceFractalDim.Calculator = new SRTraceFractalDimCal(SRTraceFractalDim);
  2792. return SRTraceFractalDim;
  2793. }
  2794. public override void DownloadValueFromPreviousItem()
  2795. {
  2796. }
  2797. protected override bool OnExecute(PointInfo args)
  2798. {
  2799. var cal = Calculator as SRTraceFractalDimCal;
  2800. if (args.VisualArea is ISRDicom)
  2801. {
  2802. var dicomvisual = args.VisualArea as ISRDicom;
  2803. bool isSRDen = dicomvisual.isSRDen();
  2804. if (args.VisualArea.Mode == null || !isSRDen)
  2805. {
  2806. return false;
  2807. }
  2808. }
  2809. else
  2810. {
  2811. var modewithurm = args.VisualArea.Mode as IModeWithURM;
  2812. if (modewithurm == null || modewithurm?.URMStyle != "URM(Den)")
  2813. return false;
  2814. }
  2815. calflag = false;
  2816. cal.calflag = false;
  2817. var preState = State;
  2818. var result = base.OnExecute(args);
  2819. if (result && preState == ItemStates.Running && State == ItemStates.Finished)
  2820. {
  2821. calflag = true;
  2822. cal.calflag = true;
  2823. }
  2824. return result;
  2825. }
  2826. protected override void OnExecuted(PointInfo args)
  2827. {
  2828. if (GeoFeature != null && Calculator != null && calflag)
  2829. {
  2830. Calculator.Calculate();
  2831. }
  2832. }
  2833. internal sealed class SRTraceFractalDimCal : Calculator<SRTraceFractalDimMeasure>
  2834. {
  2835. public bool calflag = false;
  2836. public SRTraceFractalDimCal(SRTraceFractalDimMeasure item)
  2837. : base(item)
  2838. {
  2839. }
  2840. public SRTraceFractalDimCal()
  2841. {
  2842. }
  2843. protected internal override string[] SupportedOutputKeys
  2844. {
  2845. get
  2846. {
  2847. return new[]
  2848. {
  2849. MeasureTerms.URMDenFractalDim
  2850. };
  2851. }
  2852. }
  2853. protected override void OnCalculate()
  2854. {
  2855. if (!calflag)
  2856. return;
  2857. PolyLineFeature feature = RefItem.GeoFeature;
  2858. int width = 0;
  2859. int height = 0;
  2860. double UrmPhysicalwidth = 0;
  2861. double UrmPhysicalheight = 0;
  2862. NativeArray srcArray = new NativeArray(0);
  2863. if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
  2864. {
  2865. var dicomvisual = feature.HostArea as ISRDicom;
  2866. bool isSRDen = dicomvisual.isSRDen();
  2867. if (!isSRDen)
  2868. return;
  2869. var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
  2870. ref UrmPhysicalheight);
  2871. //todo 坐标转换
  2872. srcArray.Resize(dicomdate.Length);
  2873. Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
  2874. }
  2875. else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
  2876. {
  2877. var modewithURM = feature.HostArea.Mode as IModeWithURM;
  2878. if (modewithURM.URMStyle != "URM(Den)")
  2879. return;
  2880. var date = modewithURM.UrmArray;
  2881. width = modewithURM.URMImgWidth;
  2882. height = modewithURM.URMImgHeight;
  2883. UrmPhysicalwidth = modewithURM.URMPhyWidth;
  2884. UrmPhysicalheight = modewithURM.URMPhyHeight;
  2885. srcArray.Resize(date.Length);
  2886. Marshal.Copy(date, 0, srcArray.Start, date.Length);
  2887. }
  2888. else
  2889. {
  2890. return;
  2891. }
  2892. if (srcArray.Length != 8 * width * height)
  2893. {
  2894. _delayAction.BeginInvoke();
  2895. return;
  2896. }
  2897. //todo 坐标转换
  2898. double regionwidth = feature.HostArea.ViewPort.Region.Width;
  2899. double regionheight = feature.HostArea.ViewPort.Region.Height;
  2900. var points = RefItem.GeoFeature.Points;
  2901. List<DPoint> ImagePoint = new List<DPoint>();
  2902. for (int i = 0; i < points.Count; i++)
  2903. {
  2904. var point = SRPointTrans.TransPointS2I(points[i], regionwidth, regionheight,
  2905. UrmPhysicalwidth, UrmPhysicalheight, width, height);
  2906. if (point.X < 0 || point.X > width || point.X < 0 || point.X > width)
  2907. continue;
  2908. ImagePoint.Add(point);
  2909. }
  2910. int outPointsNum = 0;
  2911. var urmcal = feature.HostArea.Mode as IURMCal;
  2912. if (urmcal == null || ImagePoint.Count < 3)
  2913. return;
  2914. double roivel = urmcal.GetSRTraceFractalDim(srcArray.Start, width, height, ImagePoint);
  2915. Outputs[0].UpdateDescription(Outputs[0].Name);
  2916. feature.UpdateValue(Outputs[0], RoundValue(roivel, GetResultDigits(PrimaryOutput)), Unit.None);
  2917. }
  2918. }
  2919. }
  2920. public class SRVelMeasure : Location
  2921. {
  2922. internal SRVelMeasure(ItemMeta meta, IMeasureItem parent) :
  2923. base(meta, parent, false)
  2924. {
  2925. }
  2926. // Methods 
  2927. protected override bool OnExecute(PointInfo args)
  2928. {
  2929. if (args.VisualArea is ISRDicom)
  2930. {
  2931. var dicomvisual = args.VisualArea as ISRDicom;
  2932. bool isSRVel = dicomvisual.isSRVel();
  2933. if (args.VisualArea.Mode == null || !isSRVel)
  2934. {
  2935. return false;
  2936. }
  2937. }
  2938. else
  2939. {
  2940. var modewithurm = args.VisualArea.Mode as IModeWithURM;
  2941. if (modewithurm == null || modewithurm?.URMStyle != "URM(Vel)")
  2942. return false;
  2943. }
  2944. return base.OnExecute(args);
  2945. }
  2946. internal static Location CreateSRVelMeasure(ItemMeta meta, IMeasureItem parent)
  2947. {
  2948. if (meta == null || meta.BaseType != MeasureTypes.SRLoactionVel)
  2949. {
  2950. throw new ArgumentException();
  2951. }
  2952. SRVelMeasure location = new SRVelMeasure(meta, parent);
  2953. location.Calculator = new SRVelMeasure.SRVelCal(location);
  2954. return location;
  2955. }
  2956. #region Nested Classes 
  2957. internal class SRVelCal : LocationCal, IGeoCalculator
  2958. {
  2959. #region Properties 
  2960. protected internal override string[] SupportedOutputKeys
  2961. {
  2962. get { return new[] { "SRVel" }; }
  2963. }
  2964. #endregion Properties 
  2965. #region Methods 
  2966. // Constructors 
  2967. internal SRVelCal(Location item)
  2968. : base(item)
  2969. {
  2970. }
  2971. protected internal SRVelCal()
  2972. {
  2973. }
  2974. // Methods 
  2975. protected override void OnCalculate()
  2976. {
  2977. // throw new NotImplementedException();
  2978. }
  2979. public void Calculate(PointInfo pointInfo)
  2980. {
  2981. LocationFeature feature = RefItem.GeoFeature;
  2982. int width = 0;
  2983. int height = 0;
  2984. double UrmPhysicalwidth = 0;
  2985. double UrmPhysicalheight = 0;
  2986. double UrmMinVel = 0;
  2987. IntPtr buffer = new IntPtr();
  2988. if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)
  2989. {
  2990. var dicomvisual = feature.HostArea as ISRDicom;
  2991. bool isSRVel =dicomvisual.isSRVel();
  2992. if (!isSRVel)
  2993. return;
  2994. var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth, ref UrmPhysicalheight);
  2995. int size = dicomdate.Length;
  2996. buffer = Marshal.AllocHGlobal(size);
  2997. Marshal.Copy(dicomdate, 0, buffer, size);
  2998. UrmMinVel = dicomvisual.GetSRMinVel();
  2999. }
  3000. else if(feature.HostArea.Mode is IModeWithURM)
  3001. {
  3002. var modewithurm = feature.HostArea.Mode as IModeWithURM;
  3003. if(modewithurm.URMStyle!="URM(Vel)")
  3004. return;
  3005. var date = modewithurm.UrmArray;
  3006. width = modewithurm.URMImgWidth;
  3007. height = modewithurm.URMImgHeight;
  3008. UrmPhysicalwidth = modewithurm.URMPhyWidth;
  3009. UrmPhysicalheight = modewithurm.URMPhyHeight;
  3010. UrmMinVel = modewithurm.URMMinVel;
  3011. int size = date.Length;
  3012. buffer = Marshal.AllocHGlobal(size);
  3013. Marshal.Copy(date, 0, buffer, size);
  3014. }
  3015. else
  3016. {
  3017. return;
  3018. }
  3019. double regionwidth = feature.HostArea.ViewPort.Region.Width;
  3020. double regionheight = feature.HostArea.ViewPort.Region.Height;
  3021. DPoint curPoint = SRPointTrans.TransPointS2I(feature.Point, regionwidth, regionheight,
  3022. UrmPhysicalwidth, UrmPhysicalheight, width, height);
  3023. if (curPoint.X < 0 || curPoint.X > width || curPoint.Y < 0 || curPoint.Y > height)
  3024. return;
  3025. var curptr = buffer + sizeof(double) * ((int)curPoint.X + (int)curPoint.Y * width);
  3026. double[] curvel = new double[1];
  3027. Marshal.Copy(curptr, curvel, 0, 1);
  3028. var velvalue = curvel[0];
  3029. velvalue += UrmMinVel;
  3030. if (velvalue < 0.01)
  3031. velvalue = 0;
  3032. feature.UpdateValue(PrimaryOutput, RoundValue(velvalue, GetResultDigits(PrimaryOutput)), Unit.mms);
  3033. }
  3034. #endregion Methods 
  3035. }
  3036. #endregion Nested Classes 
  3037. }
  3038. public class URMDen : ProtocolItem
  3039. {
  3040. internal URMDen(ItemMeta meta, IMeasureItem parent = null) : base(meta, true, parent)
  3041. {
  3042. }
  3043. internal static URMDen Create(ItemMeta meta, IMeasureItem parent)
  3044. {
  3045. if (meta == null || meta.BaseType != MeasureTypes.URMDen)
  3046. {
  3047. throw new ArgumentException();
  3048. }
  3049. var item = new URMDen(meta, parent);
  3050. item.Calculator = new URMDenCal(item);
  3051. return item;
  3052. }
  3053. internal class URMDenCal : Calculator<URMDen>
  3054. {
  3055. protected internal override string[] SupportedOutputKeys => new[] { "URMDen" };
  3056. public URMDenCal()
  3057. {
  3058. }
  3059. public URMDenCal(URMDen item) : base(item)
  3060. {
  3061. }
  3062. protected override void OnCalculate()
  3063. {
  3064. if (RefItem.Feature != null)
  3065. {
  3066. RefItem.Feature.Values.Clear();
  3067. if (PrimaryOutput != null)
  3068. {
  3069. RefItem.Feature.UpdateValue(PrimaryOutput.Name, new StringValue(PrimaryOutput.Name) { Description = PrimaryOutput.Description });
  3070. }
  3071. }
  3072. }
  3073. }
  3074. }
  3075. public class URMVel : ProtocolItem
  3076. {
  3077. internal URMVel(ItemMeta meta, IMeasureItem parent = null) : base(meta, true, parent)
  3078. {
  3079. }
  3080. internal static URMVel Create(ItemMeta meta, IMeasureItem parent)
  3081. {
  3082. if (meta == null || meta.BaseType != MeasureTypes.URMVel)
  3083. {
  3084. throw new ArgumentException();
  3085. }
  3086. var item = new URMVel(meta, parent);
  3087. item.Calculator = new URMVelCal(item);
  3088. return item;
  3089. }
  3090. internal class URMVelCal : Calculator<URMVel>
  3091. {
  3092. protected internal override string[] SupportedOutputKeys => new[] { "URMVel" };
  3093. public URMVelCal()
  3094. {
  3095. }
  3096. public URMVelCal(URMVel item):base(item)
  3097. {
  3098. }
  3099. protected override void OnCalculate()
  3100. {
  3101. if (RefItem.Feature != null)
  3102. {
  3103. RefItem.Feature.Values.Clear();
  3104. if (PrimaryOutput != null)
  3105. {
  3106. RefItem.Feature.UpdateValue(PrimaryOutput.Name, new StringValue(PrimaryOutput.Name) { Description = PrimaryOutput.Description});
  3107. }
  3108. }
  3109. }
  3110. }
  3111. }
  3112. public class FractalDimSR: URMDensityMeasure
  3113. {
  3114. internal FractalDimSR(ItemMeta meta, IMeasureItem parent = null) : base(meta, parent)
  3115. {
  3116. }
  3117. internal static FractalDimSR CreateFractalDimSR(ItemMeta meta, IMeasureItem parent)
  3118. {
  3119. if (meta.BaseType != MeasureTypes.FractalDimSR)
  3120. {
  3121. throw new ArgumentException();
  3122. }
  3123. var item = new FractalDimSR(meta, parent);
  3124. return item;
  3125. }
  3126. }
  3127. public class DensitySR : URMDensityMeasure
  3128. {
  3129. internal DensitySR(ItemMeta meta, IMeasureItem parent = null) : base(meta, parent)
  3130. {
  3131. }
  3132. internal static DensitySR CreateDensitySR(ItemMeta meta, IMeasureItem parent)
  3133. {
  3134. if (meta.BaseType != MeasureTypes.DensitySR)
  3135. {
  3136. throw new ArgumentException();
  3137. }
  3138. var item = new DensitySR(meta, parent);
  3139. return item;
  3140. }
  3141. }
  3142. public class URMDensityMeasure : MultiMethodItem
  3143. {
  3144. internal URMDensityMeasure(ItemMeta meta, IMeasureItem parent = null) : base(meta, parent)
  3145. {
  3146. }
  3147. internal static URMDensityMeasure CreateURMDensityMeasure(ItemMeta meta, IMeasureItem parent)
  3148. {
  3149. if (meta.BaseType != MeasureTypes.URMDensityMeasure)
  3150. {
  3151. throw new ArgumentException();
  3152. }
  3153. var item = new URMDensityMeasure(meta, parent);
  3154. return item;
  3155. }
  3156. }
  3157. public class URMVelMeasure : URMDensityMeasure
  3158. {
  3159. internal URMVelMeasure(ItemMeta meta, IMeasureItem parent = null) : base(meta, parent)
  3160. {
  3161. }
  3162. internal static URMVelMeasure CreateURMVelMeasure(ItemMeta meta, IMeasureItem parent)
  3163. {
  3164. if (meta.BaseType != MeasureTypes.URMVelMeasure)
  3165. {
  3166. throw new ArgumentException();
  3167. }
  3168. var item = new URMVelMeasure(meta, parent);
  3169. return item;
  3170. }
  3171. }
  3172. }